How to keep the data source updated in all WPF custom elements?

I have a WPF application with one main window .

This window has a series of buttons that form a menu and a space in which custom controls are loaded at runtime .

However, if a user modifies data (stored in an XML file) in one custom control and then switches to another custom control, the user does not see the updated data in the new custom control . The user has to restart the application to see the changes.

This is how my view is bound to the ModelView, which in turn receives data from the model (ObservableCollection):

<UserControl.Resources>
    <local:CustomersViewModel x:Key="CustomersDataProvider"/>
</UserControl.Resources>

<ListBox 
    ItemsSource="{Binding Path=GetAll, Source={StaticResource CustomersDataProvider}}" 
    ItemTemplate="{StaticResource CustomersDataTemplate}"/>

      

So how can I now, when the data binding is only defined in XAML, tell the browser to retrieve the data from the viewmodel (possibly in a code-behind-class constuctor)?

0


a source to share


2 answers


The problem is probably due to the resource being declared in your UserControl resources. This means that each UserControl will have its own copy of the resource and they won't sync. Consider using a shared resource.



0


a source


Have you tried setting Mode = TwoWay on a binding?



0


a source







All Articles