控件重新定位如何取决于同一面板中的其他控件可见性 [英] How control re-position depends on other control visibility in same panel

查看:27
本文介绍了控件重新定位如何取决于同一面板中的其他控件可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈面板中有两个按钮.最初 B1 按钮在顶部,然后是 B2.我将从代码中动态更改按钮可见性,以便当我更改隐藏的 B1 可见性时,B2 将排在首位.我怎样才能实现这个功能.

I have two buttons inside a stack panel. Initially B1 button is on top, then B2. I will change button visibility dynamically from code so that, when I change B1 visibility hidden, then B2 will come on top. How can I achieve this functionality.

    <Grid>
      <StackPanel >
        <Button Content="B1" Height="20" Width="100" Visibility="Visible"/>
        <Button Content="B2" Height="20" Width="100" Visibility="Visible"/>
     </StackPanel>
    </Grid>

推荐答案

首先你把 Statckpanel 去掉,然后放到一个 Grid 中,你就可以实现尝试这样的事情.

First you remove the Statckpanel and put then in a Grid and you can achieve Try something like this.

        <Grid>
            <Button Content="B1" Height="20" Width="100" Visibility="Visible" Click="Button_Click" x:Name="B1" />
            <Button Content="B2" Height="20" Width="100" Visibility="Visible" x:Name="B2" Click="B2_Click" />
        </Grid>


    private void Button_Click(object sender, RoutedEventArgs e)
    {
        B1.Visibility = System.Windows.Visibility.Hidden;
        B2.Visibility = System.Windows.Visibility.Visible;
    }

    private void B2_Click(object sender, RoutedEventArgs e)
    {
        B2.Visibility = System.Windows.Visibility.Hidden;
        B1.Visibility = System.Windows.Visibility.Visible;
    }

这应该会给你类似的行为.根据您的使用变化

This should give you similar behaviour. Change according to your use

这篇关于控件重新定位如何取决于同一面板中的其他控件可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆