WPF: TextTrimming on a ContentPresenter

后端 未结 2 1389
长发绾君心
长发绾君心 2021-01-04 13:36

Is there a simple way to just get TextTrimming to work with a ContentPresenter?

I have implict styles for TextBlock and AccessText that have TextTrimming set to Cha

2条回答
  •  遥遥无期
    2021-01-04 14:18

    Implicit Styles for elements that derive from UIElement, but not Control, are not applied if the element is defined in a control's Template unless the implict Style is defined in the application Resources. The same holds true for TextBlocks used by ContentPresenter.

    For example, in the following XAML the TextBlock that is ultimately used to present the button's content will not get the implicit Style:

    
        
    
    
        

    If you take that exact same Style and move it to the application's Resources, then both will be red:

    
        
    
    

    So you can either move your implicit Style to application resources, which is generally not a good idea. Or you can customize the display for the specific scenario you have. This can include adding an implicit DataTemplate, or customizing a control's Template.

    If you can provide more information, then it would be easier to know which is the best approach.

提交回复
热议问题