How to create a WPF path that stretches in place

I would like to create a WPF control for a window tab, and I want it to have a specific shape. Something like that;

      +------------------------------+
      |                              |
*     |                              |
      |                              |
   +--+                              +--+
6  |                                    |  6
   +------------------------------------+   
     6       stretching section       6

So, the small tabs at the bottom left and bottom right have a fixed size; About 6x6. But now I want the central part to extend to the width of any container into which I inserted it.

I am using the Path object at the moment, but I cannot figure out how to get the stretch section, or even if Path is the right way.

Can anyone suggest a better way to create this kind of semi-attractable shape?

+3
source share
3 answers

, "StretchStackPanel", StackPanel. :

public class StretchStackPanel : StackPanel
{
    public static DependencyProperty StretchDependencyProperty = DependencyProperty.Register("Stretch", typeof(StretchMode), typeof(StretchStackPanel));

    protected override Size MeasureOverride(Size availableSize)
    {
        var baseSize = base.MeasureOverride(availableSize);

        if (availableSize.Width != double.PositiveInfinity && (Stretch & StretchMode.Horizontal) == StretchMode.Horizontal )
        {
            baseSize.Width = availableSize.Width;    
        }
        if (availableSize.Height != double.PositiveInfinity && (Stretch & StretchMode.Vertical) == StretchMode.Vertical)
        {
            baseSize.Height = availableSize.Height;
        }

        return baseSize;
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        var baseSize = base.ArrangeOverride(finalSize);

        if ((Stretch & StretchMode.Horizontal) == StretchMode.Horizontal )
        {
            baseSize.Width = finalSize.Width;    
        }

        if ((Stretch & StretchMode.Vertical) == StretchMode.Vertical)
        {
            baseSize.Height = finalSize.Height;
        }
        return baseSize;
    }

    [Category("Layout")]
    public StretchMode Stretch
    {
        get
        {
            return (StretchMode)GetValue(StretchDependencyProperty);
        }
        set
        {
            SetValue(StretchDependencyProperty, value);
        }
    }
}

, . , . StretchStackPanel.

+3

? . , .

+3

I think you should override the MeasureOverride method in your control and get the DesiredSize of your content (by calling the content / child measurement method). Then you can create your Path based on this size.

+2
source

Source: https://habr.com/ru/post/1703087/


All Articles