开发者

WPF Refresh StaticResource

I have a ComboBox that has it's ItemsSource bound as

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

Where documentTemplates is

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

The problem I have is that the document template开发者_StackOverflow社区s defined in the database could be changed by other areas of the application (or indeed by another user) and so I want to have the ItemsSource requery each time. At the moment, once the resource has been populated it will never requery. I assume that this is because it is a StaticResource, but if I swap this for a DynamicResource I get

A 'DynamicResourceExtension' cannot be set on the 'Source' property of type 'Binding'. A 'DynamicResrouceExtension' can only be set on a DependencyProperty or a DependencyObject

How should I go about fixing this?


Keep your XAML as is and whenever a requery is needed call Refresh on the ObjectDataProvider.

(FindResource("documentTemplates") as ObjectDataProvider).Refresh();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜