datatemplate in app.xaml is not getting picked up without any styles?

后端 未结 2 894
离开以前
离开以前 2021-01-01 15:07

I have a DataTemplate in app.xaml that binds a view to a viewmodel.


    

        
2条回答
  •  悲&欢浪女
    2021-01-01 15:28

    Answered a similar question here. The question is not exactly the same, that one contained merged dictionaries being skipped but it's most likely the same bug.

    This is an optimization bug, see this link.

    On the creation of every object in XAML, if a default style is present (i.e. style w/ a key of Type) that style should be applied. As you can imagine there are several performance optimizations to make that (implied) lookup a light weight as possible. One of them is that we don’t look inside Resource Dictionaries unless they are flagged as “containing default Styles”. There is a bug: if all your default styles are nested in merged dictionaries three levels deep (or deeper) the top dictionary does not get flagged so the search skips it. The work around is to put a default Style to something, anything, in the root Dictionary.

    I see you've already found the workaround as well, just add a default dummy style in App.xaml. It doesn't have to have any setters etc, something like this will do as well