我有一个附加了样式模板的按钮,我希望在代码隐藏中进行修改。
这是按钮:
<Button x:Name="But6" Content="6" Foreground="White" Style="{StaticResource ExitButton}"/>
这是样式模板:
<Style x:Key="ExitButton" x:Name="exitButtonStyle" TargetType="{x:Type Button}">
<Setter x:Name="exitButtonSetter" Property="Template">
<Setter.Value>
<ControlTemplate x:Name="exitButtonTemplate" TargetType="Button">
<Grid>
<Rectangle x:Name="exitButtonRectangle" Stroke="#6d6d6d" StrokeThickness="2" Fill="Gray" HorizontalAlignment="Right" VerticalAlignment="Bottom" RadiusX="15" RadiusY="15" Width="500" Height="150" Margin="10,10,-600,10"/>
<Label x:Name="exitButtonLabel" Content="Exit" FontFamily="Comic Sans MS" Foreground="DarkGray" FontSize="22" Margin="75,0,0,0" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="exitButtonRectangle" Property="Fill" Value="#9c9c9c"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如何在代码隐藏中修改矩形的Margin属性或模板的Label内容?
我失败的尝试:
But6.ExitButton.exitButton.Template.exitButtonRectangle.Margin = new Thickness(10, 10, 10, 10);