WPF Refresh StaticResource

I have a ComboBox in which it is linked to ItemsSource as

ItemsSource="{Binding Source={StaticResource documentTemplates}}" 

Where documentTemplates

 <ObjectDataProvider x:Key="documentTemplates" ObjectType="{x:Type Core:DataHelper}" MethodName="GetDocumentTemplates"/> 

The problem is that the document templates defined in the database can be modified by other areas of the application (or, indeed, by another user), and therefore I want to request ItemsSource every time. At the moment, as soon as the resource is populated, it will never demand. I assume this is because it is a StaticResource, but if I change it to DynamicResource, I get

A 'DynamicResourceExtension' cannot be set in the Source property of the Binding type. "DynamicResrouceExtension" can only be set to DependencyProperty or DependencyObject

How can I fix this?

+4
source share
1 answer

Keep your XAML as is, and whenever a request is required, call Refresh on ObjectDataProvider.

 (FindResource("documentTemplates") as ObjectDataProvider).Refresh(); 
+11
source

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


All Articles