WPF: How to autosize Path to its container?

前端 未结 4 599
闹比i
闹比i 2021-01-17 09:37

I have a Path that must resize to its StackPanel container.


    

        
4条回答
  •  既然无缘
    2021-01-17 10:22

    Ensure that your path is smaller than your StackPanel.

    Easiest way for a very easy path will be to move the comma in every number (i.e. divide everything by 10 or 100 in TranslateZ), or for more complicated paths add a LayoutTransform (lower the scaling factor as needed):

    
        
              
                   
              
        
    
    

    Some Remarks:

    I had a similar problem, with a button template containing a path. The button's "auto" size was determined by the path, because the path had the largest dimensions of the template content.

    This in itself might not turn out as a problem, because if you specify the button's height/width, or if the button's Horizontal-/VerticalAlignment is set to stretch, of course the path will scale.

    For other values of Horizontal-/VerticalAlignment however, the button size gets determined by the amount of space required by its content, which in my case resulted in a button with the path's original dimensions.

提交回复
热议问题