我需要社区工具包的帮助。 MVVM利用信使进行不同观点的沟通。 我的问题是,与此同时,用户可以两次(因为台式照相机)对送信员的 t工作进行简单执行,我需要登记我的看法模式,而只是为了特定观点模式而倾听(我很难找到文件上的任何实例)。
Thank you for any help in advance.
I tried to simplify the code to include only needed parts of it.
用户ListView.xaml
<UserControl x:Class="ProjectIdeas.Core.Users.View.UsersListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:viewmodel="clr-namespace:ProjectIdeas.Core.Users.ViewModel"
xmlns:local="clr-namespace:ProjectIdeas.Core.Users.View"
mc:Ignorable="d">
<UserControl.DataContext>
<viewmodel:UsersListViewModel />
</UserControl.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<syncfusion:SfDataGrid
ItemsSource="{Binding Users}"
SelectedItem="{Binding SelectedUser}" />
<local:UserDetailView Grid.Column="1" />
</Grid>
</UserControl>
用户ListViewModel.cs
public sealed partial class UsersListViewModel : ObservableObject
{
[ObservableProperty]
private UserModel? _selectedUser;
partial void OnSelectedUserChanged(UserModel? value)
{
WeakReferenceMessenger.Default.Send(new UserDetailViewSelectedUserChangedMessage(value));
}
}
用户
public sealed partial class UserDetailViewModel : ObservableObject, IRecipient<UserDetailViewSelectedUserChangedMessage>
{
[ObservableProperty]
private UserModel? _user;
public UserDetailViewModel()
{
WeakReferenceMessenger.Default.Register<UserDetailViewSelectedUserChangedMessage>(this);
}
public void Receive(UserDetailViewSelectedUserChangedMessage message)
{
User = message.Value;
}
}
用户详细意见
public class UserDetailViewSelectedUserChangedMessage : ValueChangedMessage<UserModel?>
{
public UserDetailViewSelectedUserChangedMessage(UserModel? value) : base(value) {}
}