0

将 Catel Framework 与 Xceed.Wpf.Toolkit.PropertyGrid 一起使用时出现错误。错误在于,如果我从 ViewModelBase 继承,PropertyGrid 是不可见的自定义属性如果我从 ModelBase 继承,则一切正常

这段代码工作得很好

    public class PersonViewModel : ModelBase
{
    [DisplayName(@"Название")]
    [Description(@"Название стратегии")]
    [Category(@"Основные")]
    [PropertyOrder(0)]
    public string Person
    {
        get { return GetValue<string>(PersonProperty); }
        set { SetValue(PersonProperty, value); }
    }

    public static readonly PropertyData PersonProperty = RegisterProperty("Person", typeof(string));
}

但是这段代码不起作用

    public class PersonViewModel : ViewModelBase
{
    [DisplayName(@"Название")]
    [Description(@"Название стратегии")]
    [Category(@"Основные")]
    [PropertyOrder(0)]
    public string Person
    {
        get { return GetValue<string>(PersonProperty); }
        set { SetValue(PersonProperty, value); }
    }

    public static readonly PropertyData PersonProperty = RegisterProperty("Person", typeof(string));
}

XAML

 <xcad:LayoutAnchorable ContentId="alarms"
                                               Title="Alarms"
                                               >
                            <xctk:PropertyGrid BorderThickness="0"
                                               SelectedObject="{Binding Path=SelectedObject}"
                                               ShowSearchBox="False"
                                               ShowSortOptions="False"
                                               Width="Auto"
                                               AutoGenerateProperties="False"
                                               NameColumnWidth="150">
                                <xctk:PropertyGrid.PropertyDefinitions>
                                    <xctk:PropertyDefinition Name="Person" />
                                </xctk:PropertyGrid.PropertyDefinitions>
                            </xctk:PropertyGrid>
                        </xcad:LayoutAnchorable>
4

1 回答 1

1

使用视图模型时,向其中添加视图很重要。您已经创建了 PersonViewModel,但没有 PersonView。

如果您不想为 Person 创建单独的视图,则不需要 PersonViewModel。我们认为在视图模型中创建子视图模型不是正确的方法。这就是我们在 Catel 中创建嵌套用户控件解决方案的原因。

您在这里有 2 个选项:

  1. 创建一个自定义 PersonView(它将与 PersonViewModel 一起动态工作)
  2. 保留 PersonModel(就是这样,一个人的模型)
于 2013-07-05T09:05:49.810 回答