如何隐藏面板?

时间:2013-08-01 11:43:20

标签: c# .net wpf

!我正在使用Wpf。我想显示两个面板,如果一个是可见的,其他人应该隐藏。两者都应该保持相同的差距。下面的图片将详细解释我的问题。

enter image description here

谢谢, 安妮

任何人都可以指导我如何编码吗?

6 个答案:

答案 0 :(得分:2)

尝试这样的事情......

        newButton.Click += (o, ev) =>
        { 
            panelA.Visibility = System.Windows.Visibility.Hidden;
            panelB.Visibility = System.Windows.Visibility.Visible;
        }
        closeButton.Click += (o, ev) =>
        {
            panelB.Visibility = System.Windows.Visibility.Hidden;
            panelA.Visibility = System.Windows.Visibility.Visible;
        };

答案 1 :(得分:1)

我没有VS,所以它应该是这样的

  <Button x:Name="ToggleButton" Click="ToggleButton_Click"></Button>



 private void ToggleButton_Click(object sender, RoutedEventArgs e)
        {
            if (Panel1.Visibility == System.Windows.Visibility.Visible)
            {
                Panel2.Visibility = System.Windows.Visibility.Visible;
                Panel1.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                Panel2.Visibility = System.Windows.Visibility.Collapsed;
                Panel1.Visibility = System.Windows.Visibility.Visible;
            }
        }

答案 2 :(得分:0)

代码非常简单:

Panel1.Visibility = System.Windows.Visibility.Hidden;
Panel2.Visibility = System.Windows.Visibility.Visible;

答案 3 :(得分:0)

试试这个(假设您正在使用MVVM模式)

使用2个公共属性(bool)绑定堆栈面板的可见性。在两者的set属性上,检查其visibility == true,然后将其他控件的可见性设置为false。

使用以下可见性转换器

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    bool bValue = (bool)value;
    if (bValue)
        return Visibility.Visible;
    else
        return Visibility.Collapsed;
}

在xaml上,您应该将此堆栈面板的可见性绑定为

Visibility="{Binding Panel1Visibility,Converter={StaticResource BoolToVisibilityConverter}}"

答案 4 :(得分:0)

使用此可用性转换器

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
   bool bValue = (bool)value;
   if (bValue)
     return Visibility.Visible;
   else
     return Visibility.Collapsed;
}

答案 5 :(得分:-2)

只需将panel1.hide()和panel2.show

放入