【问题标题】:Deep Property Binding with Caliburn Micro issues与 Caliburn Micro 问题的深度属性绑定
【发布时间】:2013-05-15 10:01:54
【问题描述】:

我只是不知道我做错了什么。我正在尝试在 WPF 应用程序(4.5)上使用 Caliburn Micro。尝试遵循 MVVM 的价值。

我的虚拟机具有服务和授权属性。授权具有 SelectedService 的属性。我将控件命名为x:Name=Services,当我填充Services 属性时,它们会显示在RadGridView 中,但是当您在RadGridView 中选择一个项目时,它不会将SelectedItem 绑定回我的SelectedService 属性。是因为 Services 属性在一个级别,而 SelectedService 是更深的级别,Authorizations.SelectedService

下面是我敢于发布的尽可能多的代码,而不会淹没帖子。希望这就足够了。

我觉得我已经非常接近“获得”Caliburn 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 命名控件在哪里?
  • 视图中没有一个。我曾想过,对于 Combobox 和 Datagrid,约定是它将x:Name 绑定到 VM 上用于 itemsource 的匹配属性,并在 VM 上查找名为“Selected、Active 或 Single”的属性,然后与第一个属性相同的名称。这就是我试图让它去做的事情。它从不将 Datagrid 的 SelectedItem 设置为我的 Authorization.SelectedItem 属性。
  • 什么数据网格?您有一个 RadGridView 和一个 RadDataPager。我在视图中看不到任何其他内容。
  • 抱歉,口误,我的意思是 RadGridView。

标签: c# wpf data-binding mvvm caliburn.micro


【解决方案1】:

没有开箱即用的 Telerik 约定,因为这需要依赖于 Telerik 控件。你可以看看写你自己的conventions,或者使用Caliburn.Micro.Telerik项目,它可以作为NuGet package使用。

【讨论】:

  • 很抱歉,我应该更清楚一点。我正在使用 Caliburn.Micro.Telerik 约定。它有 RadGridView 的约定,但似乎不起作用。
  • 好吧,这不是很多事情要做。你真的填充了 Services 属性吗?您的网格视图中是否有空白项目?调试时,您的输出窗口中是否出现任何绑定错误?您的问题提到了 x:Name=Authorization_SelectedService 但这在您看来无处可见。
  • 对不起,我会尽量说清楚。我将直接编辑我的帖子。非常感谢您尝试帮助我。
猜你喜欢
  • 1970-01-01
  • 2018-07-29
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-06
  • 2016-06-27
  • 1970-01-01
相关资源
最近更新 更多