I have a checkbox located in a grid with a column span of 3, where 2 of the columns are resizable, and can be resized during runtime.
I want the checkbox to show ellipsis when its text doesn't fit, but can't get this to work.
Here is my XAML code.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
...
<CheckBox IsEnabled="False" Grid.Row="2" Padding="5" Margin="11,12,0,0" Name="chkSelectedCat" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.ColumnSpan="3">
<AccessText Text="Search in selected category only." TextTrimming="CharacterEllipsis"/>
</CheckBox>
Thanks in advance for your help.
EDIT
The CheckBox in question is located within a Grid, which is in turn contained within a GroupBox, which is in a column adjacent to a column which is resized using a GridSplitter.
The problem was that the
GroupBoxallots infinite width to its child controls, as discussed at this MSDN forum thread.In fact, when setting a
MaxWidthto theCheckBox, text trimming worked and the ellipsis were displayed.However the
CheckBoxmaximum width needed to be changed during runtime.I tried using a MultiValueConverter to bind the
MaxWidthof theCheckBoxto the totalActualWidthof the three columns, but theConvertmethod was only being called during initialisation (again I think this is something to do with how theGroupBoxassigns sizes to its child controls).Anyway I managed to achieve what I wanted by removing the
ChechkBox'sAccessTextand using aTextBlockin aStackPanelin its stead, and then surrounding everything with aBorder.When the size of the
Borderis changed, I update theWidthof the StackPanel in the event handler, and the text in theTextBoxtrims accordingly.Hope this helps someone in the future (even though it is sort of a hack).
UPDATE
If you can eliminate the
StackPaneland use aGridinstead,TextTrimmingworks automatically, without having to do any event handling, as shown below.Make sure to set the
Widthof the column containing the textbox to"*", because"Auto"basically tells theTextBoxthat it can have as much space as it wants, soTextTrimmingwould not work.