none
How to exclude some enum members in the xaml when bound to a ComboBox?

    Dotaz

  • I am using VS 2010, .Net 4.0 and C#.  I want to be able to exclude certain members of an enumeration when binding the enumeration to a ComboBox control.  I seem to remember seeing a solution to this type of feature in a posting awhile back, but I can no longer find it.

    I have an enumeration like this:

    public enum MyEnum
    {
       First,
       Second,
       Third,
       Fourth,
       Fifth
    }
    

    I want to bind the enum to a ComboBox like this:

    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="MyEnumSelection">
       <ObjectDataProvider.MethodParameters>
          <x:Type TypeName="common:MyEnum"/>
       </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    
    <ComboBox IsSynchronizedWithCurrentItem="True"
    SelectedValue="{Binding Path=MyEnumProperty}" 
    ItemsSource="{Binding Source={StaticResource MyEnumSelection}}"/>
    

    I seem to remember it was possible to exclude certain members from the enum by adding some xaml syntax in the ItemsSource binding code.  I think it looked something like this:

    <ComboBox IsSynchronizedWithCurrentItem="True"
    SelectedValue="{Binding Path=MyEnumProperty}" 
    ItemsSource="{Binding Source={StaticResource MyEnumSelection}, Exclude="Fifth"}"/>
    

    Does anybody know the correct syntax to do this? Are there limitations to what can be excluded?

    Thanks, Dave


    Dave R&D SW Engineer Agilent Technologies

    9. května 2012 17:26

Všechny reakce