我有三个按钮,一个接一个地躺着。我要显示所有单击的按钮的顶部。这样我就在XAML代码中设置了 Canvas ZIndex。但我想在“隐藏代码”中执行此操作。

我的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输出和代码(检查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" />

如何在单击事件中的WPF按钮控件中更改Canvas.ZIndex属性?

最佳答案

您可以在这样的代码中设置z索引-

Panel.SetZIndex(control name, int index);

关于c# - 如何在Click事件中设置 Canvas ZIndex WPF按钮控件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20094407/

10-10 01:50