将可见性属性(视图)与布尔属性(ViewModel)绑定
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将可见性属性(视图)与布尔属性(ViewModel)绑定相关的知识,希望对你有一定的参考价值。
<!-- XAML VisibilityConverter Usage --> <Window.Resources> <vw:VisibilityConverter x:Key="VisibilityConverter" /> </Window.Resources> <Grid Visibility="{Binding MyBoolean, Converter={StaticResource VisibilityConverter}}"> ... </Grid> // C# VisibilityConverter implementation public class VisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Visibility rv = Visibility.Visible; try { var x = bool.Parse(value.ToString()); if (x) { rv = Visibility.Visible; } else { rv = Visibility.Collapsed; } } catch (Exception) { } return rv; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; } }
以上是关于将可见性属性(视图)与布尔属性(ViewModel)绑定的主要内容,如果未能解决你的问题,请参考以下文章
如何将 WPF DataGrid DataColumns 可见性绑定到 UserControl 的 ViewModel 上的属性?