我在我们的项目中定制DataGridRowGroupHeader。一切都很好,除了我不能让文本修剪。
下面是风格:
<sdk:DataGrid.RowGroupHeaderStyles>
<Style TargetType="sdk:DataGridRowGroupHeader">
<Setter Property="Cursor" Value="Arrow" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="20"/>
<Setter Property="Margin" Value="18,0,20,0"/>
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="sdk:DataGridRowGroupHeader">
<Grid Name="Root"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}"
HorizontalAlignment="Stretch"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CurrentStates">
<VisualState x:Name="Regular"/>
<VisualState x:Name="Current">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border BorderBrush="Yellow" BorderThickness="1" Visibility="Visible">
<TextBlock x:Name="txbGroupingName"
Margin="4,0,0,0"
Text="{Binding Name}"
FontSize="13"
TextTrimming="WordEllipsis"
HorizontalAlignment="Left"
Style="{StaticResource OrangeBodyText}"
/>
</Border>
<Rectangle Name="FocusVisual"
Stroke="{StaticResource BorderFocusBrush}"
StrokeThickness="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsHitTestVisible="false"
Opacity="0" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</sdk:DataGrid.RowGroupHeaderStyles>TextBlock txbGroupingName中的文本不能裁剪,看起来应该没问题。
提前感谢!
发布于 2011-02-12 05:32:07
我从林一峰那里得到了答案。RowGroupHeader固定为行的宽度。它的目的是在DataGrid内容太长时显示水平滚动条,并且可以通过这种方式查看RowGroupHeaders。当列被冻结时,问题才会出现。
因此,实际上没有解决方案,但这就是为什么文本不会动态裁剪的原因。可以在文本块上设置宽度以强制修剪,但这可能更适合于换行。
https://stackoverflow.com/questions/4951219
复制相似问题