我有三个按钮一个接一个地躺着。我想显示所有按钮的顶部,我点击。所以我在XAML Code中设置了canvas ZIndex。但我想在Code Behind中做到这一点。
我的XAML输出&代码 -
<Button Name="Button1" Canvas.ZIndex="3" Content="Button1" Canvas.Top="100" Width="163" Height="58" FontSize="26" Click="Button1_Click" />
<Button Name="Button2" Canvas.ZIndex="2" Content="Button1" Canvas.Top="100" Canvas.Left="130" Width="163" Height="58" FontSize="26" Click="Button2_Click" />
<Button Name="Button3" Canvas.ZIndex="1" Content="Button1" Canvas.Top="100" Canvas.Left="260" Width="163" Height="58" FontSize="26" Click="Button3_Click" />
我的XAML输出&amp;代码(检查ZIndex如何更改) -
<Button Name="Button1" Canvas.ZIndex="3" Content="Button1" Canvas.Top="100" Width="163" Height="58" FontSize="26" Click="Button1_Click" />
<Button Name="Button2" Canvas.ZIndex="2" Content="Button1" Canvas.Top="100" Canvas.Left="130" Width="163" Height="58" FontSize="26" Click="Button2_Click" />
<Button Name="Button3" Canvas.ZIndex="1" Content="Button1" Canvas.Top="100" Canvas.Left="260" Width="163" Height="58" FontSize="26" Click="Button3_Click" />
如何在Click事件中更改WPF按钮控件中的Canvas.ZIndex属性?
答案 0 :(得分:18)
您可以在代码中设置z索引,如this-
Panel.SetZIndex(control name, int index);
答案 1 :(得分:3)
附加属性是根据惯例使用SetPropertyName函数设置的代码。
Panel.SetZIndex(Button2, 0);
答案 2 :(得分:2)
Z-index可以像这样设置..
Panel.SetZIndex(Button2, 10);