Reputation: 3442
I have enum
public enum DocumentTypes
{
First, Second, Third, Fourth
}
How to pass values of enum
to <sys:Enum></sys:Enum>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1.Converters"
xmlns:enums="clr-namespace:WpfApplication1.Enums"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<Label Content="Test2">
<Label.Visibility>
<MultiBinding Converter="{StaticResource Converter}">
<MultiBinding.ConverterParameter>
<x:Array Type="{x:Type sys:Enum}">
<sys:Enum></sys:Enum>
</x:Array>
</MultiBinding.ConverterParameter>
<Binding ElementName="First" Path="IsChecked" />
<Binding ElementName="Second" Path="IsChecked" />
<Binding ElementName="Third" Path="IsChecked" />
<Binding ElementName="Fourth" Path="IsChecked" />
</MultiBinding>
</Label.Visibility>
</Label>
Upvotes: 4
Views: 4770
Reputation: 657
Try this:
<MultiBinding.ConverterParameter>
<x:Array Type="{x:Type sys:Enum}">
<x:Static Member="sys:Enum:YourEnumType.YourEnumValue1" />
<x:Static Member="sys:Enum:YourEnumType.YourEnumValue2" />
</x:Array>
</MultiBinding.ConverterParameter>
In my project, I have added my enumeration type namespace like:
xmlns:mod="clr-namespace:MyProject.Modal;assembly=MyProject.Modal"
where MyProject.Modal is the namespace of my enumeration definition. In this way, if you have an enumeration names "MyEnum", then you could do this:
<MultiBinding.ConverterParameter>
<x:Array Type="{x:Type mod:MyEnum}">
<x:Static Member="mod:MyEnum.Value1" />
<x:Static Member="mod:MyEnum.Value2" />
</x:Array>
</MultiBinding.ConverterParameter>
Upvotes: 0
Reputation: 334
You can add a bindable Property to your datacontext like:
public IEnumerable DocumentTypesList
{
get
{
return Enum.GetVaues(typeof(DocumentTypes));
}
}
And bind to it via:
<MultiBinding.ConverterParameter>
<Binding Path="DocumentTypesList">
</MultiBinding.ConverterParameter>
This way, if your enum gets altered, you don´t have to change any XAML representation of it.
Or if the converter always uses this explicit enum, you could reference it directly in it.
Upvotes: 0
Reputation: 9827
Do this :
<x:Array Type="{x:Type sys:Enum}">
<local:DocumentTypes>First</local:DocumentTypes>
<local:DocumentTypes>Second</local:DocumentTypes>
<local:DocumentTypes>Third</local:DocumentTypes>
</x:Array>
Upvotes: 12