Avoiding the '[Unknown]' property does not point to a DependencyObject in the path '(0). (eleven]. (2) 'wpf exception

Click OK to refresh the ListBox ItemsSource collection. For 4 or 5 clicks, it works fine, but then throws an exception, because the [Unknown] 'property does not point to DependencyObject in the path' (0). (eleven]. (2) '

I looked for him and found the reason for this.

"ElementControl overrides PrepareContainerForItemOverride and calls PrepareModel to insert a grid in _modelContainer for each Item. Later in ElementFlow.BuildTargetPropertyPath (which is called through ElementFlow.SelectItemCore β†’ LayoutBase.SelectElement β†’ Elementlement, it’s supposed to be set to ElementMeterFrameboard.ElementModelplate. when the grid was not inserted into _modelContainer. WPF calls PrepareContainerForItemOverride on ApplyTemplate. This is done only once. Elements added later are never handled this way. "

So please provide me a solution to overcome it.

+4
source share
1 answer

It looks like your itemsource collection has an item that does not have the type you want or does not contain one of the properties that your listbox item is looking for. Or perhaps if you have different classes in your collection, one of them may not have the property you are looking for as DependencyProperty. If this is simply a property, it may not work correctly.

Check all the types of objects that are in the itemssource collection, and make sure that they all have DependencyProperties, which are named by what the itemstemplate element is looking for.

+1
source

Source: https://habr.com/ru/post/1385779/


All Articles