0
votes

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>
1
That is weird. When you enable "break on all exceptions", are you sure that there are no exceptions?Geert van Horrik
Yes you are right I have an exception Could not load file or assembly "Catel.MVVM.Aero2"user45245
Those can be ignored. That is WPF trying to load the themes if available. Are there other exceptions? Can you provide a small repro?Geert van Horrik
Yes there is another exception but it exception does not affect anything. This is test project dropbox.com/s/jr2prkjb7zzwkym/WpfApplication.raruser45245

1 Answers

1
votes

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)