You can create IValueConverter
from State
toVisibility
public class StateToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (value is State)
{
State state = (State)value;
switch (state)
{
case State.Away:
case State.Gone:
return Visibility.Visible;
default:
return Visibility.Collapsed;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return State.None;
}
}
Then you bind your button to the converter
<Window.Resources>
<local:StateToVisibilityConverter x:Key="StateToVisibilityConverter"/>
</Window.Resources>
<Button Text="Hello" Visibility="{Binding Path=State, Converter={StaticResource StateToVisibilityConverter}}"/>
source
share