0

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>
user45245
  • 845
  • 1
  • 8
  • 18
  • That is weird. When you enable "break on all exceptions", are you sure that there are no exceptions? – Geert van Horrik Jul 04 '13 at 19:26
  • Yes you are right I have an exception Could not load file or assembly "Catel.MVVM.Aero2" – user45245 Jul 04 '13 at 19:35
  • 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 Jul 04 '13 at 20:45
  • Yes there is another exception but it exception does not affect anything. This is test project https://www.dropbox.com/s/jr2prkjb7zzwkym/WpfApplication.rar – user45245 Jul 05 '13 at 05:23

1 Answers1

1

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)
Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32