我有一个包含一些Path
的ControlTemplate
。我希望这些Path
可以拉伸并填充它所在的控件,例如Button
。我该怎么做?
目前我的代码如下:
<ControlTemplate x:Key="SomeTemplate" TargetType="Button">
<Canvas Background="AliceBlue">
<Path Data="M 99.5,50 A 49.5,49.5 0 1 1 0.5,50 A 49.5,49.5 0 1 1 99.5,50 z"
Fill="White" Stroke="Black" StrokeThickness="1" />
<Path Data="M 15,50 C 17.5,22.5 47.5,22.5 50,50 C 52.5,77.5 82.5,77.5 85,50"
Stroke="Black" StrokeThickness="1" />
</Canvas>
</ControlTemplate>
...
<Button Template="{StaticResource SomeTemplate}" Height="120" Width="120" />
我知道ScaleTransform
的StrechX
和StretchY
属性,但它们只是原始Path
大小的等比例缩放。
我应该使用值转换器吗?或者可能使用相对于父元素大小的绑定形式?
Viewbox
的作用。 :-) 将具有其固有大小(如Path
或Canvas
)的内容拉伸到其容器的大小。 - Gábor