I have 3 ViewModel
: base, and 2 child. I want with the help of ViewModelLocator
be able to manage the property that is in the base VM from the children so that they work with the same instance, and not each with its own, and accordingly both react to the changes. Specifically, in the base VM there is a bool property, which should change from other VMs.
Used this article ( https://msdn.microsoft.com/en-us/library/hh821028.aspx ). I created App.xaml
instance of ViewModelLocator
in App.xaml
, the class itself must give an instance of the required VM when I do Binding
on it on Xaml
.
UPD
Locator
public class ViewModelLocator { private BaseViewModel baseVm; public BaseViewModel BaseVm { get { return new BaseViewModel(); } } }
App.xaml
<viewModels:ViewModelLocator x:Key="ViewModelLocator"/>
MainPage.xaml
elements which are zabindeny on the necessary me sv-va from BaseViewModel
<Image Visibility="{Binding IsFilterImgVisible, Source={StaticResource ViewModelLocator} ,Converter={StaticResource BooleanToVisibilityConverter}}"/> <controls:ImageManipulatorControl Visibility="{Binding IsUserControlVisibile, Converter={StaticResource BooleanToVisibilityConverter}}"> </controls:ImageManipulatorControl>
With a control, there is generally a separate problem, with such a record, something transparent is superimposed on a part of the screen (I suspect that this is control, although the bool
initially false
)
In the base VM, there are bool
properties that change from the child VMs using the word this.
but no result
App.xaml
, I can immediately refer to them or need to writeBaseViewModel = new BaseViewModel()
- SmiLeBaseViewModel
- SmiLe