
Hello,
I'm testing the PropertyGrid to see if it fit my needs. I have "complex objects" where I means that I must display multiple objects (so using PropertyGrid.SelectedObjects property) which have collections of objects, and so on.
Suppose this is my model (for brevity I have removed the INotifyPropertyChanged implementation):
public class Carico : INotifyPropertyChanged
{
private double _v1;
public double v1 { get { return _v1; } set { _v1 = value; NotifyPropertyChanged("v1"); } }
private double _v2;
public double v2 { get { return _v2; } set { _v2 = value; NotifyPropertyChanged("v2"); } }
private double _v3;
public double v3 { get { return _v3; } set { _v3 = value; NotifyPropertyChanged("v3"); } }
}
public class Asta : INotifyPropertyChanged
{
private ObservableCollection<Carico> _Carichi;
[Category("Carichi")]
public ObservableCollection<Carico> Carichi { get { return _Carichi; } set { _Carichi = value; NotifyPropertyChanged("Carichi"); } }
public Asta()
{
this.Carichi = new ObservableCollection<Carico>();
this.Carichi.Add(new Carico() { v1 = 321.0, v2 = 999, v3 = 9812 });
this.Carichi.Add(new Carico() { v1 = 987.0, v2 = 999, v3 = 1133 });
this.Carichi.Add(new Carico() { v1 = 159.0, v2 = 999, v3 = 4561 });
}
}
public class Contesto : INotifyPropertyChanged
{
private ObservableCollection<Asta> _Aste;
public ObservableCollection<Asta> Aste { get { return _Aste; } set { _Aste = value; NotifyPropertyChanged("Aste"); } }
public Contesto()
{
this.Aste = new ObservableCollection<Asta>();
this.Aste.Add(new Asta());
this.Aste.Add(new Asta());
}
}
as you can see, for semplicity, when a instance of class Contesto is created it add 2 elements in the "Aste" collection, Asta add 3 instances of Class Carico in the Asta.Carichi Collection.
My needs are that when the PropertyGrid show the Contesto.Aste Collection (via the SelectedObjects=Contesto.Aste) it display a category "Carichi" with 3 TextBoxes (one for each v1, v2, v3 properties of Class Carico) where common values for all the Carico instances of all the Asta instances are shown.
And of course when I change the value in one textbox it is setted in all the Carico instances for all the Asta instances.
I'm trying to subclass the TypeDescriptorFactory and overriding the GetProperties(object[] values, DataFactoryOptions options) but i'm not so skilled and don't know how to merge objects/properties.
I'm also creating a CategoryEditor with relative template but I think I need to correctly merge the properties/object...
<pg:PropertyGrid
AreAttachedPropertiesBrowsable="False"
CollectionDisplayMode="EditableInline"
AreNestedCategoriesSupported="True"
PropertyExpandability="ForceSimple"
IsSummaryVisible="True"
SummaryCanAutoSize="True"
SummaryHeight="Auto"
SelectedObjects="{Binding Aste }"
Grid.Column="1" Grid.Row="1"
>
<pg:PropertyGrid.CategoryEditors >
<pg:CategoryEditor Description="Definizione dei Carichi" Category="Carichi"
EditorTemplate="{StaticResource ResourceKey=TF}" >
<pg:CategoryEditor.Properties>
<pg:CategoryEditorProperty PropertyName="Carichi" />
</pg:CategoryEditor.Properties>
</pg:CategoryEditor>
</pg:PropertyGrid.CategoryEditors>
</pg:PropertyGrid>
<DataTemplate x:Key="TF">
<ItemsControl ItemsSource="{Binding Properties , RelativeSource={RelativeSource AncestorType={x:Type pg:ICategoryEditorDataAccessor}}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" >
<Grid x:Name="GrdmainTemplCarichi" DataContext="{Binding Values[0]}">
<Grid.RowDefinitions>
<RowDefinition Height="24*"/>
<RowDefinition Height="24*"/>
<RowDefinition Height="240*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Grid.Row="0">
<TextBox Text="{Binding [0].v1}"/>
<TextBox Text="{Binding [0].v2}"/>
<TextBox Text="{Binding [0].v3}"/>
</StackPanel>
</Grid>
<Grid x:Name="GrdmainTemplCarichi1" DataContext="{Binding Values}">
<Grid.RowDefinitions>
<RowDefinition Height="24*"/>
<RowDefinition Height="24*"/>
<RowDefinition Height="240*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Grid.Row="0">
<TextBox Text="{Binding [0].v1}"/>
<TextBox Text="{Binding [0].v2}"/>
<TextBox Text="{Binding [0].v3}"/>
<TextBox Text="{Binding v1}"/>
<Label Content="------"/>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
any help appreciated, hope this can be done with PropertyGrid
thanks, Franco