Skip to content

Instantly share code, notes, and snippets.

@droyad
Created August 21, 2012 02:36
Show Gist options
  • Save droyad/3410893 to your computer and use it in GitHub Desktop.
Save droyad/3410893 to your computer and use it in GitHub Desktop.
// Not written in an IDE
class MyViewModel
{
MyViewModelStepEnum CurrentStep { get; set; }
enum MyViewModelStepEnum {
Step 1, Step2
}
}
XAML:
<Window.Resources>
<local:EnumToVisibilityConverter x:Key="CurrentStepConverter" EnumType="{x:Type local:MyViewModelStepEnum}">
</Window.Resources>
<Grid Visibility="{Binding CurrentStep, Converter={StaticResource CurrentStepConverter}, ConverterParameter=Step2}" />
Converter:
public class EnumToVisibilityConverter : IValueConverter
{
public Type EnumType { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(parameter == null)
// throw
var parameterValue = Enum.Parse(EnumType, parameter);
return value == parameterValue ? Visibility.Visible : Visiblity.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment