
I am trying to force a datagrid property of type collection (ItemContainer) and referenced in the associated ViewModel to Auto expand in a PropertyGrid by using a databinding from a custom IsExpandable property defined in a Model ItemContainer.
I have tried to Set the property IsExpanded in XAML from ItemContainer.IsExpanded as follow:
View
<propgrid:PropertyGrid x:Name="StrategyGrid" Grid.Column="0"
SelectedObject="{Binding GridItems}"
CollectionDisplayMode="Expandable"
PropertyExpandability="ForceSimple">
<propgrid:PropertyGrid.Resources>
<Style x:Key="{x:Type primitives:PropertyGridDataAccessorItem}"
TargetType="{x:Type primitives:PropertyGridDataAccessorItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Property">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</DataTrigger>
</Style.Triggers>
</Style>
</propgrid:PropertyGrid.Resources>
ViewModel
public class StrategyGridViewModel : DataGridViewModelBase
{
Public GridItems GridItems { get; set; }
GridItems = new GridItems();
GridItems.Parameters = new ItemContainer();
GridItems.Parameters.Add("Parameter1", 1);
GridItems.Parameters.Add("Parameter2", 2);
GridItems.Parameters.IsExpanded = true;
}
Model GridItems
public class StrategyGridItems
{
[Category("Category")]
[Description("This is a description")]
public ItemContainer Parameters { get; set; }
}
Model ItemContainer
public class ItemContainer : Dictionary<string, object>
{
public bool IsExpanded { get; set; }
}
I believe the XAML <Style > is correct except for the DataBinding to ItemContainer.IsExpanded; any idea what I am doing wrong here?