[英]Split one button into two separate buttons after a click event in WPF
I am just curious if it is possible to replace a button into two buttons which the two buttons occupy the place of the original single buttons after a click event?我只是好奇是否可以将一个按钮替换为两个按钮,这两个按钮在单击事件后占据原始单个按钮的位置? Also after the click event of one of the two buttons, is it possible to revert to the original view where there is only one button?同样在两个按钮之一的点击事件之后,是否可以恢复到只有一个按钮的原始视图?
So it looks like the fission of one button into two buttons and then the fusion of two buttons into one button again.所以看起来就像一个按钮裂变成两个按钮,然后两个按钮再次融合成一个按钮。
welcome to StackOverflow.欢迎使用 StackOverflow。 Yes, it is quite possible, and in the simplest form, not even that difficult.是的,这很有可能,而且以最简单的形式,甚至没有那么难。 It goes something like this:它是这样的:
Of course, if you want to add stuff like animations and so, it will be a lot more complicated.当然,如果你想添加动画之类的东西,那会复杂得多。
in .xaml在.xaml
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btn_big" Grid.ColumnSpan="2" Click="Click_big"/>
<Button x:Name="btn_small1" Grid.Column="1" Visibility="Hidden" Click="Click_small"/>
<Button x:Name="btn_small2" Grid.Column="2" Visibility="Hidden" Click="Click_small"/>
</Grid>
in .cs在.cs
private void Click_big(object sender, MouseButtonEventArgs e)
{
btn_big.Visibility=Visibility.Hidden;
btn_small1.Visibility=Visibility.Visible;
btn_small2.Visibility=Visibility.Visible;
}
private void Click_small(object sender, MouseButtonEventArgs e)
{
btn_big.Visibility=Visibility.Visible;
btn_small1.Visibility=Visibility.Hidden;
btn_small2.Visibility=Visibility.Hidden;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.