You could multi-bind the cell's content to the actual number, to the width of the containing column, and to the desired size of the TextBlock
. Then use a converter to convert select the content accordingly. Pseduo-XAML:
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="_textBlock">
<TextBlock.Content>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding Path="."/>
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Ancestor, AncestorType={GridViewColumn}}"/>
<Binding Path="DesiredSize.Width" ElementName="_textBlock"/>
</MultiBinding>
</TextBlock.Content>
</TextBlock>
</Datatemplate>
</GridViewColumn.CellTemplate>
Pseduo-code:
public class MyConverter : IMultiValueConverter
{
public object Convert(...)
{
object content = values[0];
double actualWidth = (double)values[1];
double desiredWidth = (double)values[2];
if (desiredWidth > actualWidth)
{
return "######";
}
return content;
}
}
Other than that, you could write your own TextBlock
subclass that does a similar thing automatically, and then use that inside each column template.
HTH,
Kent