-5

!我正在使用 Wpf。我想显示两个面板,如果一个是可见的,另一个应该隐藏。两者应处于相同的边距。下面的图片将详细解释我的问题。

在此处输入图像描述

谢谢,安妮

谁能指导我如何编码?

4

6 回答 6

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;
        };
于 2013-08-01T11:56:51.663 回答
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;
            }
        }
于 2013-08-01T11:56:16.050 回答
0

代码非常简单:

Panel1.Visibility = System.Windows.Visibility.Hidden;
Panel2.Visibility = System.Windows.Visibility.Visible;
于 2013-08-01T11:50:25.763 回答
0

试试这个(假设您使用的是 MVVM 模式)

将两个堆栈面板的可见性与 2 个公共属性(布尔)绑定。并在两者的设置属性上,检查其可见性是否==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}}"
于 2013-08-01T11:52:28.037 回答
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;
}
于 2013-08-01T12:01:17.507 回答
-2

简单地说 panel1.hide() 和 panel2.show

于 2013-08-01T11:53:59.780 回答