Margin can't be modified in AdvancedTextBlock inside PropertyGridItem

Grids for WPF Forum

Posted 2 years ago by Guillaume Guimond-Croteau
Version: 19.1.3
Platform: .NET 5.0
Environment: Windows 11 (64-bit)
Avatar

Hi,

I am trying to modify the PropertyStyle, but I can't manage to modify the Margin of the AdvancedTextBlock. Here is the code:

<grids:PropertyGrid.ItemContainerStyleSelector>
                <grids:PropertyGridItemStyleSelector>
                    <grids:PropertyGridItemStyleSelector.PropertyStyle>
                        <Style TargetType="grids:PropertyGridItem">
                            <Style.Resources>
                                <Style TargetType="shared:AdvancedTextBlock">
                                    <Setter Property="Margin" Value="0" />
                                    <Setter Property="Foreground" Value="Blue" />
                                </Style>
                            </Style.Resources>
                        </Style>
                    </grids:PropertyGridItemStyleSelector.PropertyStyle>
                </grids:PropertyGridItemStyleSelector>
            </grids:PropertyGrid.ItemContainerStyleSelector>

To test that the TargetType works I also changed the foreground color. It changed correctly, but the margin is still not changing from the orininal 5,3,1,3. Is it a bug or is there something I can do to work around this?

[Modified 2 years ago]

Comments (1)

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

Hello,

The default value of the PropertyGrid.DefaultStringNameTemplate property is:

<DataTemplate>
	<shared:AdvancedTextBlock x:Name="textBlock" Margin="5,3,1,3" Text="{Binding DisplayName}" 
								TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
					
	<DataTemplate.Triggers>
		<DataTrigger Binding="{Binding IsReadOnly}" Value="True">
			<Setter TargetName="textBlock" Property="Opacity" Value="0.7" />
		</DataTrigger>
	</DataTemplate.Triggers>
</DataTemplate>

I'd recommend just changing that DataTemplate property value, since your Style won't override the explictly set Margin in that DataTemplate.


Actipro Software Support

The latest build of this product (v24.1.3) 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.