Converter with Dependency Properties

后端 未结 2 798
情书的邮戳
情书的邮戳 2021-01-24 10:35

I have problems implementing a custom DependencyObject:

I need a converter which sets or unsets a enum flag in a bound property. Therefore I created a IValueConverter d

2条回答
  •  鱼传尺愫
    2021-01-24 11:29

    Conclusion

    I decided to solve the problem using two UserControls; FlagControl and EnumerationEditorControl.

    The FlagControl has two dependency properties

    • Flag (System.Enum): Determines which flag is set/cleared by the control
    • Value(System.Enum): Bound to the propery/value in which the flag is set/cleared.

    The EnumerationEditorControl has one dependency property:

    • Value(System.Enum): The propery/value in which flags are set.

    The EnumerationEditorControl uses a DataTemplate to instantiate FlagControls. The DataTemplate binds the FlagControl.Flag property to the DataContext and the FlagControl.Value property to the EnumerationEditorControl.Value property.

    This way I don't need a converter and logic is clearly separated.

    Thanks for the suggestions, comments and replies!

提交回复
热议问题