开发者

WPF Binding Enum to Command Parameters

开发者 https://www.devze.com 2022-12-18 04:41 出处:网络
I am trying to bind a Enum to CommandParameters of a button.This cannot be static due to the fact that the button occurs in a ItemsControl.

I am trying to bind a Enum to CommandParameters of a button. This cannot be static due to the fact that the button occurs in a ItemsControl.

Here is the Datatemplate:

<DataTemplate>
   <Button Command="{Binding MyCom开发者_Python百科mand}" CommandParameters="{Binding MyEnumParameter}" Text="{Binding MyText}" />
</DataTemplate>

I am not sure what I need to do as the exception is Cannot convert enum to String. My guess is I will need a ValueConverter for this please verify if that is the only route for this.


Yes, using a ValueConverter would be the right thing to do. This thread has en example you can use.

0

精彩评论

暂无评论...
验证码 换一张
取 消