简体   繁体   中英

How to set canvas ZIndex WPF button control in Click Event?

I have three buttons lying one by one. I want to show top of all button, which i click. So that I have set canvas ZIndex in XAML Code. But I want to do this in Code Behind.

My XAML Output & Code -

图片

<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" />

My XAML Output & Code (Check How the ZIndex was Changed)-

图片

<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" />

How I change the Canvas.ZIndex property in WPF button control in Click Event?

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

Panel.SetZIndex(control name, int index);

按照惯例,使用SetPropertyName函数从代码中设置附加属性。

Panel.SetZIndex(Button2, 0);

Z索引可以这样设置。

 Panel.SetZIndex(Button2, 10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM