Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting multiple enum flags in XAML

Is there any way to set multiple enum flags (that are traditionally separated by | in codebehind) in XAML? I tried something like:

<ns:SomeControl Flags="FlagA|FlagB" /> 

but that didn't work.

like image 707
K Mehta Avatar asked Oct 10 '11 21:10

K Mehta


2 Answers

WPF does support this through a type converter. It can be done by using a comma in between enum values:

<ns:SomeControl Flags="FlagA,FlagB" /> 
like image 74
FunnyItWorkedLastTime Avatar answered Sep 19 '22 13:09

FunnyItWorkedLastTime


You can use the accepted answer code

<ns:SomeControl Flags="FlagA,FlagB" /> 

But you also need add a TypeConverter attribute on the property to make it work

[TypeConverter(typeof(EnumConverter))] //yeah, this line Public MyEnum Flags { ... 
like image 36
Mr. Squirrel.Downy Avatar answered Sep 19 '22 13:09

Mr. Squirrel.Downy