Setting Property in a PropertyGrid Style through Data Binding

Grids for WPF Forum

Posted 6 years ago by Aulin
Version: 13.1.0583
Avatar

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?

Comments (2)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Aulin,

The DataContext of the PropertyGridDataAccessorItem will be an instance of IPropertyDataAccessor your Style above (because the DataTrigger is only used for properties). So your Binding is looking for an IsExpanded property on the object that implements IPropertyDataAccessor, of which there isn't one (unless you implemented your own custom DataFactory and accessors).

You probably intended to bind to the object from which the property was created, in which case you'd use:

<Setter Property="IsExpanded" Value="{Binding Value.IsExpanded, Mode=TwoWay}" />

 But if that doesn't help, please send along a completely sample project to our support email and we can take a closer look.


Actipro Software Support

Posted 6 years ago by Aulin
Avatar

Thanks for your response, that was exactly my problem.

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.