WPF data binding to dictionary with enum key

前端 未结 2 999
小鲜肉
小鲜肉 2021-01-07 06:37

I have a solution with a couple of projects. In one project, is my model that has an enum called ModelEnum.

Then in my WPF project I have a ViewModel which has a Dic

相关标签:
2条回答
  • 2021-01-07 07:16

    replace

    (model:ModelEnum)ModelEnum.Enum1].Value
    

    with

    (model:ModelEnum)Enum1]
    

    Then try. I hope it will work.

    0 讨论(0)
  • 2021-01-07 07:24

    Just to add to the potential pitfalls with this, I had issues binding without the explicit "Path="

    i.e.

    {Binding ValuesDictionary[(model:ModelEnum)Enum1]}
    

    doesn't work, but:

    {Binding Path=ValuesDictionary[(model:ModelEnum)Enum1]}
    

    works as expected, although the designer (or maybe ReSharper) still complains about syntax errors.

    0 讨论(0)
提交回复
热议问题