NullToVisibilityConverter 如果不为空则使可见 [英] NullToVisibilityConverter make visible if not null

查看:22
本文介绍了NullToVisibilityConverter 如果不为空则使可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在列表视图中隐藏和显示 SelectedItem 的属性网格

Want to hide and show property grid for SelectedItem in listview

<UserControl xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
      <ListView>
         <!--here is list view-->
      </ListView>
      <xctk:PropertyGrid SelectedObject="{Binding Active}" Visibility="{Binding Active, Converter=NullToVisibilityConverter}" >  
   </xctk:PropertyGrid>
</UserControl>

所以我需要转换器并在可见性属性转换器中使用它.有什么帮助吗?

So I need converter and use it in visibility property converter. Any help?

推荐答案

public class NullVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value == null ? Visibility.Hidden : Visibility.Visible;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

然后在您的 XAML 资源中引用 NullVisibilityConverter.

Then reference the NullVisibilityConverter in your XAML Resources.

<StackPanel.Resources>
  <simpleXamlContent:NullVisibilityConverter x:Key="NullToVisibilityConverter"/>
</StackPanel.Resources>

这篇关于NullToVisibilityConverter 如果不为空则使可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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