Xceed WPF propertyGrid Element für erweiterte Sammlung anzeigen
Wie zeige ich ein @ ObservableCollection<>
von benutzerdefinierten Objekten im Xceed WPF PropertyGrid, in dem jedes Listenelement erweitert werden kann, um die Eigenschaften der benutzerdefinierten Objekte anzuzeigen. (dh:
---- PropertyGrid -----
CoreClass
(+/-) ObservableCollection <CustomClass>
(+/-) CustomClass.Object1
Property1: Wert
Property2: Value
…
PropertyN: Wert
(+/-) CustomClass.Object2
Property1: Wert
Property2: Value
…
PropertyN: Wert
Wenn ich @ benut[ExpandableObject]
auf derObservableCollection<>
Es wird nur die Eigenschaft Counts angezeigt.
Bearbeiten (Code hinzugefügt)
MainWindow.xaml:
<Window x:Class="PropGridExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PropGridExample"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<xctk:PropertyGrid x:Name="PropertyGrid" SelectedObject="{Binding BindingItem}"></xctk:PropertyGrid>
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
MainWindowViewModel mwvm = new MainWindowViewModel();
this.DataContext = mwvm;
InitializeComponent();
}
}
MainWindowViewModel.cs
public class MainWindowViewModel
{
public Item BindingItem { get; set; }
public MainWindowViewModel()
{
BindingItem = new Item();
}
public class Item
{
public int ID { get; set; }
[ExpandableObject()]
public ObservableCollection<CustomClass> Classes { get; set; }
public Item()
{
ID = 1;
, Classes = new ObservableCollection<CustomClass>();
Classes.Add(new CustomClass() { Name = "CustomFoo" });
}
}
public class CustomClass
{
public string Name { get; set; }
[ExpandableObject()]
public ObservableCollection<type> Types { get; set; }
public CustomClass()
{
Types = new ObservableCollection<type>();
Types.Add(new type() { name = "foo", value = "bar" });
Types.Add(new type() { name = "bar", value = "foo" });
}
}
public class type
{
public string name { get; set; }
public string value { get; set; }
}
}