user45245
user45245

Reputation: 905

Catel MVVM xctk:PropertyGrid = Error

I have an error when I use Catel Framework together with Xceed.Wpf.Toolkit.PropertyGrid. The error consists in the fact that the PropertyGrid is invisible custom attributes if I inherit from ViewModelBase If I inherit from ModelBase that all is normal

This code work wery well

    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));
}

but this code didn't work

    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>

Upvotes: 0

Views: 332

Answers (1)

Geert van Horrik
Geert van Horrik

Reputation: 5724

When using a view model, it is important to add a view to it. You have created a PersonViewModel, but there is no PersonView.

If you don't want to create a separate view for Person, then there is no need for a PersonViewModel. We think it is not the right way to create sub-view models inside a view model. That's why we created the nested user controls solution in Catel.

You have 2 options here:

  1. Create a custom PersonView (which will work dynamically with the PersonViewModel)
  2. Keep the PersonModel (which is what it is, a model of a person)

Upvotes: 1

Related Questions