K Mehta
K Mehta

Reputation: 10543

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.

Upvotes: 34

Views: 8900

Answers (2)

Mr. Squirrel.Downy
Mr. Squirrel.Downy

Reputation: 1167

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
{ ...

Upvotes: 1

RandomActsOfCode
RandomActsOfCode

Reputation: 3285

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" />

Upvotes: 60

Related Questions