当我从逻辑中加载了一个列表并想使用其他viewModel从该列表中选择一些值时,我遇到了一个问题。
public List<ContactsListModel> ExampleList
{
get => _exampleList;
set
{
_exampleList = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ExampleList)));
}
}
上面有我的列表,其中包含一些数据。我不想再次加载它。如何在另一个viewModel中从中获取值?
您可以将视图模型的实例传递到要使用它的页面,从那里可以访问它。
1。您要访问的Viewmodel:
Pushasync(new YourPage(this)); //Passed the instance of your view model
2。您要访问的页面:
public partial class DemoClass
{
YourViewModel demo_;
public DemoClass()
{
InitializeComponent();
}
public DemoClass(Yourviewmodel demo)
{
InitializeComponent();
demo_ = demo; // access the instance and all its properties
}
}