简体   繁体   English

在 WPF 中的单击事件后将一个按钮拆分为两个单独的按钮

[英]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:它是这样的:

  1. Make a UI with 3 buttons.使用 3 个按钮制作 UI。
  2. Hide two of the, leave the last one visible.隐藏其中的两个,让最后一个可见。
  3. On click of the visible button, make the other two buttons visible and hide the clicked button.单击可见按钮时,使其他两个按钮可见并隐藏单击的按钮。
  4. On click of one of the two buttons, revert the above procedure.单击两个按钮之一时,恢复上述过程。

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.

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