TextTrimming in name cell

Grids for WPF Forum

Posted 10 years ago by RS
Version: 4.5.0485
Avatar
Can you tell me how I go about setting the TextTrimming property on the name column so that if the column is too small the text shows the ellipsis when trimmed? I tried using a custom template but the TextTrimming doesn't seem to have any effect for Textblocks in the name cell.

RS

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm not sure how you specified the custom template, but you can customize the name cells in the same manner as the value cells. Therefore, you can add the following code to your PropertyGrid:
<propgrid:PropertyGrid.PropertyEditors>
   <propgrid:PropertyEditor>
      <propgrid:PropertyEditor.NameTemplate>
         <DataTemplate>
            <TextBlock Margin="4,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Center"
               TextTrimming="CharacterEllipsis"
               Text="{Binding DisplayName, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}}" />
         </DataTemplate>
      </propgrid:PropertyEditor.NameTemplate>
   </propgrid:PropertyEditor>
</propgrid:PropertyGrid.PropertyEditors>
This overrides the default DataTemplate used by the PropertyGrid for all properties. You could also target specific properties or property types by setting the PropertyName or PropertyType on the PropertyEditor element.

Hope this helps.


Actipro Software Support

Posted 10 years ago by RS
Avatar
Thanks for the reply. It turns out that the problem was caused by the TextBlock being contained in a horizontal StackPanel (TextBlock in a StackPanel doesn't trim). I've changed it to a Grid and the trimming works fine now.

RS

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Right. If you have a TextBlock in a horizontal StackPanel, then it will get all the space it needs.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.