Wouterdek/NodeNetwork

WPF Item Template errors

FabianNitsche opened this issue · 3 comments

When running the ExampleShaderEditorApp I get the following ItemTemplate errors:

System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type MenuItem
System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type Separator
System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type MenuItem

The error 26 originates from mixing views with view models in SearchableContextMenuView.xaml. The solution here is to create ViewModels for SearchMenuItem, Separator and the Commands added below the search (ContainerBelowSearch). The latter could just be LabeledCommands again.

I can provide a fix, but want to discuss it first.

Right, so while WPF reports this as an error, it's default action is to just add the views to the menu, which is precisely the intended behavior. I get why you want to fix this, as this depends on a grey area of the WPF API. However, I'm tempted to just leave this be, as 'fixing' this might add more complexity and break stuff, while it works perfectly fine now. The current solution also has the nice benefit that users can add whatever to ContainerBelowSearch, instead of being restricted to a specific type like LabeledCommand which doesn't support everything MenuItem has to offer.

Have you encountered any functional issues with the current code, apart from the error message?

As you said, it works perfectly, thanks for that. And I did not encounter any functional issue. It is pure cosmetics. So it may not be worth to change anything.

I just thought, that it may be helpful to minimize "non-meaningful" errors. So that the WPF developer does not get used to them and starts ignoring them.

And while writing this and playing around with the code. I found a very easy and non-breaking fix. Check PR #100. It seems while WPF forces the DataTemplate from ItemTemplate on all, it just treats the DataTemplate in the Resources as optional. I tested it by adding Foreground=red to the DataTemplate. Seems to work. Please check.

Jup, seems to work well. Very nice, thanks!