TextBox TextTrimming
wpf, xaml
Solution
Try a style like this (I've added background colours to make the change obvious):
<Style TargetType="TextBox">
<Setter Property="Background" Value="Yellow" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}" Value="false">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<TextBlock Text="{TemplateBinding Text}" TextTrimming="CharacterEllipsis" Background="Red" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
Problem
I would like to apply a `TextTrimming` option on a `TextBox` (Not a `TextBlock`). The compiler tells me that the `TextTrimming` options is not a valid property of the `Textbox`. I could do a fancy control that is a `Textblock` and once it's clicked will become a `Textbox` and conversely go back to being a `Textblock` once the focus is lost. Before going this way I would like to know if a built-in function already exists (or is there a smarter way) to allow you to do that? EDIT: What I want to have in the end is a `TextBox` which is trim (the full content will be display in a tooltip) but when the user select the `TextBox` (enter in "edit mode") the full content will be display (without trim) therefore the user will be able to modify the full text. when the `TextBox` lost the focus (go back to "view mode") the content will be trim again. Thanks