
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 2.17 KB | hits: 11 | expires: Never
Binding an enumeration value to a 3-state checkbox
Enum NodeStatusTypes
Undefined
Grant
Deny
End Enum
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<l:EnumToTriStateConverter x:Key="TriConverter" />
</StackPanel.Resources>
<CheckBox IsThreeState="True" IsChecked="{Binding Path=Permission, Converter={StaticResource TriConverter}, ConverterParameter={x:Static l:NodeStatusTypes.Grant}}" />
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Permission}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Public Class EnumToTriStateConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Return value.Equals(parameter)
End Function
Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Dim retVal As NodeStatusTypes = Nothing
Select Case value
Case Nothing
retVal = NodeStatusTypes.Undefined
Case True
retVal = NodeStatusTypes.Grant
Case False
retVal = NodeStatusTypes.Deny
End Select
Return retVal
End Function
End Class
Public Function Convert(value As Object, targetType As System.Type,
parameter As Object,
culture As System.Globalization.CultureInfo) As Object
Implements System.Windows.Data.IValueConverter.Convert
Dim retVal As Object = Nothing;
Select Case value
Case NodeStatusTypes.Undefined
retVal = Nothing
Case NodeStatusTypes.Grant
retVal = True
Case NodeStatusTypes.Deny
retVal = False
End Select
Return retVal
End Function