Caliburn.Micro MVVM Framework中具有SelectedItem的对象绑定

问题描述 投票:0回答:1

我有以下型号:

public class Profile
    {
        public string name { get; set; }
        public Member casemanager { get; set; }
        public Member assistant { get; set; }
    }

public class Member 
    {
        public int Id { get; set; }
        public int Type{ get; set; }
        public string Name { get; set; }
    }

在我的ViewModel中,我有以下对象:

  • 从数据库中填充的名为Profiles的ObservableCollection<Profile>
  • 当然是Profile类型的SelectedProfile;
  • 从数据库填充的名为ListCaseManagers和ListAssistants的两个成员列表。

每个对象都实现了Caliburn.Micro的NotifyOfPropertyChange方法,并设置了属性和支持字段。

The View:

<StackPanel>
 <ListView ItemsSource="{Binding Profiles}" SelectedItem="{Binding SelectedProfile}" DisplayMemberPath="name" SelectionMode="Single" />
 <ComboBox ItemsSource="{Binding ListCaseManagers}" SelectedItem="{Binding SelectedProfile.casemanager }"  IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name"/>
 <ComboBox ItemsSource="{Binding ListAssistants}" SelectedItem="{Binding  SelectedProfile.assistant}" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name"/>
</StackPanel>

在此XAML中,我认为每个ComboBox的SelectedItem都将直接绑定到SelectedProfile的案例管理员/助手,每次使用ListView修改SelectedProfile时都会进行更改,但是即使SelectedProfile似乎也不选择组合框中的项目.casemanager和SelectedProfile.assistant不为null。

我想念的是什么?是否可以通过Caliburn.Micro使用约定的简单方法?

c# wpf mvvm caliburn.micro
1个回答
0
投票

在组合框中显示了几个属性,这些属性可让您修改列表中的SelectedItem。

SelectedValuePath =“ casemanager”SelectedValue =“ {Binding SelectedProfile.casemanager}”

更新:我假设您正在使用3个集合。并且它们包含不同的对象(尝试通过GetHash()比较它们)

© www.soinside.com 2019 - 2024. All rights reserved.