我只是没有弄清楚我做错了什么。我正尝试在WPF应用程序(4.5)上使用Caliburn Micro。试图遵循MVVM的价值。Deep Property与Caliburn Micro问题绑定
我的虚拟机具有服务和授权的属性。授权具有SelectedService的属性。我已经命名了我的控件x:Name=Services
,当我填充它们显示在RadGridView中的服务属性时,但是当您在RadGridView中选择一个项目时,它不会将SelectedItem
绑回我的SelectedService
属性。是否因为服务属性是一个级别而SelectedService
是更深的级别,Authorizations.SelectedService
?
下面是我的代码尽可能多我敢发布没有洪泛的职位。希望这已经足够了。
我觉得我很接近“获得”卡利Micro和MVVM一般....
public class Authorization:BindableBase
{
public int ID
{
get { return this.id; }
set
{
this.id = value;
this.OnPropertyChanged();
}
}
public Service SelectedService
{
get { return this.selectedService; }
set
{
this.selectedService = value;
OnPropertyChanged();
}
}
public Member ActiveMember
{
get { return this.activeMember; }
set
{
this.activeMember = value;
this.OnPropertyChanged();
}
}
}
然后CreateAuthViewModel具有用于填充可能的选择所谓的服务是模型,也是一个属性:
[Export(typeof(IScreen))]
public class CreateAuthViewModel : Screen, IHandle<MessageNotifier>
{
public Authorization Authorization
{
get { return this.authorization; }
set
{
this.authorization = value;
NotifyOfPropertyChange();
}
}
public BindableCollection<Service> Services
{
get { return services; }
set
{
services = value;
NotifyOfPropertyChange();
}
}
最后我看来,CreateAuthView:
<UserControl x:Name="CreateAuthUserControl"
x:Class="Green.Views.CreateAuthView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cal="http://www.caliburnproject.org">
<telerik:RadExpander>
<StackPanel>
<telerik:RadGridView x:Name="Services"
IsReadOnly="True"
SelectionMode="Extended"
ScrollViewer.CanContentScroll="True" />
<telerik:RadDataPager x:Name="ServicesDataPager"
PageSize="10"
VerticalAlignment="Bottom"
Source="{Binding Items, ElementName=Services}" />
</StackPanel>
</telerik:RadExpander>
</UserControl>
您的视图中的哪个位置是您的Authorization_SelectedService命名控件? – devdigital
视图中没有一个。我曾经想过,在Combobox和Datagrid中,惯例是将'x:Name'绑定到虚拟机上的项目源的匹配属性,并在VM上查找名为“Selected,Active或Single”的属性和第一个属性同名。这就是我想要做的。它永远不会将Datagrid的SelectedItem设置为我的'Authorization.SelectedItem'属性。 –
什么DataGrid?你有一个RadGridView和一个RadDataPager。我看不到其他任何东西。 – devdigital