zoukankan      html  css  js  c++  java
  • DataGrid 支持字符截断显示

    DataGrid支持截断时, 需要分2部分, DataGridColumnHeader和DataGridCell。
    1)创建上述2部分的ControlTemplate 。
    2)把其中的ContentPresenter改为TextBlock
    3)使用TextTrimming属性

    xaml code like this:


    <ControlTemplate x:Key="DataGridCellControlTemplate" TargetType="{x:Type DataGridCell}">
    <Border Background="{TemplateBinding Background}" SnapsToDevicePixels="True" BorderThickness="0" Height="{TemplateBinding Tag}">
                <TextBlock
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    Margin="{TemplateBinding Padding}"
                    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}"
                    TextTrimming="CharacterEllipsis"
                    />
    </Border>
    </ControlTemplate>

    <ControlTemplate x:Key="PublicDataGridColumnHeaderControlTemplate" TargetType="{x:Type DataGridColumnHeader}">
    <Grid>
    <VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="SortStates">
    <VisualState x:Name="Unsorted"/>
    <VisualState x:Name="SortAscending">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="path1">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    <VisualState x:Name="SortDescending">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="path">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
                <TextBlock
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    Margin="{TemplateBinding Padding}"
                    Text="{TemplateBinding Content}"
                    TextTrimming="CharacterEllipsis"
                    utility:TextBlockTrimming.AutoTooltip="True"/>
    <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{DynamicResource PublicDataGridHeaderLeftGripperStyle}" Margin="0,3" Visibility="{TemplateBinding SeparatorVisibility}"/>
    <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{DynamicResource PublicDataGridHeaderRightGripperStyle}" Margin="0,3" Background="#FF838282" Visibility="{TemplateBinding SeparatorVisibility}"/>
    <Path x:Name="path" Data="M5.0000001,0 L10,7.0000002 0,7.0000002 z" Fill="Black" HorizontalAlignment="Right" Height="4" Margin="0,2,2,0" Stretch="Fill" Stroke="{x:Null}" VerticalAlignment="Top" Width="6" Visibility="Hidden"/>
    <Path x:Name="path1" Data="M5,0 L10,6.9999999 0,6.9999999 z" Fill="Black" HorizontalAlignment="Right" Height="4" Margin="0,2,2,0" RenderTransformOrigin="0.5,0.499999995742525" Stretch="Fill" Stroke="{x:Null}" VerticalAlignment="Top" Width="6" Visibility="Hidden" >
    <Path.RenderTransform>
    <TransformGroup>
    <ScaleTransform ScaleY="-1" ScaleX="1"/>
    <SkewTransform AngleY="0" AngleX="0"/>
    <RotateTransform Angle="0"/>
    <TranslateTransform/>
    </TransformGroup>
    </Path.RenderTransform>
    </Path>
    </Grid>
    <ControlTemplate.Triggers>
    <Trigger Property="SeparatorVisibility" Value="Hidden">
    <Setter Property="Visibility" TargetName="PART_LeftHeaderGripper" Value="Hidden"/>
    <Setter Property="Visibility" TargetName="PART_RightHeaderGripper" Value="Hidden"/>
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
  • 相关阅读:
    iOS側拉栏抽屉效果Demo
    Juce源代码分析(九)应用程序基类ApplicationBase
    Android获取手机方向
    2014手机号码归属地数据库
    自译Solr in action中文版
    HUD 2031: 进制转换
    《学习opencv》笔记——矩阵和图像操作——cvConvertScale,cvConvertScaleAbs,cvCopy and cvCountNonZero
    Xcode5.1.1+ios 7.1.2 免证书真机调试
    《你不知道的JavaScript》读书笔记(二)词法作用域
    python生成word中文字体
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3170976.html
Copyright © 2011-2022 走看看