如何在调整RadGridView列的大小时添加工具提示

时间:2011-10-31 18:31:53

标签: c# wpf silverlight telerik tooltip

我似乎找不到任何合适的方法来添加ToolTip来显示Telerik RadGridView控件的列宽(以像素为单位)。任何人对如何做到这一点都有任何想法?

2 个答案:

答案 0 :(得分:2)

我会尝试为将ToolTip属性绑定到列的ActualWidth属性的所有列添加样式

<Style TargetType="{x:Type telerik:GridViewBoundColumnBase}">
    <Setter Property="ToolTip" Value="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
</Style>

答案 1 :(得分:1)

经过一段时间的搜索和尝试不同的事情,我终于找到了一个有效的解决方案。雷切尔上面的回答让我朝着正确的方向前进。这是我发现的解决方案。

<Style TargetType="{x:Type telerik:GridViewHeaderCell}">
        <Setter Property="Template" Value="{DynamicResource GridViewHeaderCellControlTemplate1}"/>
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF5B5B5B" Offset="1"/>
                    <GradientStop Color="#FF868686"/>
                    <GradientStop Color="#FF4F4F4F" Offset="0.42"/>
                    <GradientStop Color="#FF0E0E0E" Offset="0.43"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush" Value="#FF848484"/>
        <Setter Property="BorderThickness" Value="0,0,1,1"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="5,0,3,0"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="DropMarkPen">
            <Setter.Value>
                <Pen Brush="White" Thickness="2"/>
            </Setter.Value>
        </Setter>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
    </Style>
    <ControlTemplate x:Key="GridViewHeaderCellControlTemplate1" TargetType="{x:Type telerik:GridViewHeaderCell}">
        <Grid x:Name="PART_HeaderCellGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Border x:Name="GridViewHeaderCell" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2">
                <Border BorderBrush="#FF4B4B4B" BorderThickness="1" Background="{TemplateBinding Background}"/>
            </Border>
            <Border x:Name="GridViewHeaderCell_Over" BorderBrush="#FFFFC92B" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" Opacity="0">
                <Border BorderBrush="White" BorderThickness="1">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFFFFBA3" Offset="1"/>
                            <GradientStop Color="#FFFFFBDA" Offset="0"/>
                            <GradientStop Color="#FFFFD25A" Offset="0.43"/>
                            <GradientStop Color="#FFFEEBAE" Offset="0.42"/>
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
            </Border>
            <Border x:Name="GridViewHeaderCell_Selected" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" Opacity="0">
                <Border.BorderBrush>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF616161" Offset="0"/>
                        <GradientStop Color="#FF989898" Offset="1"/>
                    </LinearGradientBrush>
                </Border.BorderBrush>
                <Border BorderThickness="1">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFB69A78"/>
                            <GradientStop Color="#FFFFE17A" Offset="0.126"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFFFD74E" Offset="0.996"/>
                            <GradientStop Color="#FFFFDCAB" Offset="0.17"/>
                            <GradientStop Color="#FFFFB062" Offset="0.57"/>
                            <GradientStop Color="#FFFFD18F" Offset="0.56"/>
                            <GradientStop Color="#FFFFBA74"/>
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
            </Border>
            <ContentControl x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="{TemplateBinding IsTabStop}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <ContentControl.Style>
                    <Style TargetType="{x:Type ContentControl}">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
            <Path x:Name="PART_SortIndicator" Grid.ColumnSpan="2" Data="M0,0L1,0 2,0 3,0 4,0 5,0 5,1 4,1 4,2 3,2 3,3 2,3 2,2 1,2 1,1 0,1 0,0z" Fill="Black" HorizontalAlignment="Center" Height="3" Margin="0,3,0,0" Opacity="0" RenderTransformOrigin="0.5,0.5" Stretch="Fill" VerticalAlignment="Top" Width="5">
                <Path.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleY="-1" ScaleX="1"/>
                        <SkewTransform AngleY="0" AngleX="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
            <telerik:FilteringDropDown x:Name="PART_DistinctFilterControl" Grid.Column="1" IsTabStop="False" Margin="0,0,8,0" Visibility="{TemplateBinding FilteringUIVisibility}">
                <telerik:StyleManager.Theme>
                    <telerik:Office_BlackTheme/>
                </telerik:StyleManager.Theme>
            </telerik:FilteringDropDown>
            <Thumb x:Name="PART_LeftHeaderGripper" Grid.ColumnSpan="2" HorizontalAlignment="Left" IsTabStop="{TemplateBinding IsTabStop}"/>
            <Thumb x:Name="PART_RightHeaderGripper" Grid.ColumnSpan="2" HorizontalAlignment="Right" IsTabStop="{TemplateBinding IsTabStop}"/>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True"/>
                    <Condition Property="SortingState" Value="None"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="GridViewHeaderCell_Over">
                                <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.EnterActions>
                <MultiTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="GridViewHeaderCell_Over">
                                <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.ExitActions>
                <Setter Property="Foreground" Value="Black"/>
            </MultiTrigger>
            <Trigger Property="SortingState" Value="Ascending">
                <Setter Property="Foreground" Value="Black"/>
                <Setter Property="Opacity" TargetName="PART_SortIndicator" Value="1"/>
                <Setter Property="LayoutTransform" TargetName="PART_SortIndicator">
                    <Setter.Value>
                        <ScaleTransform ScaleY="1" ScaleX="1"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="Opacity" TargetName="GridViewHeaderCell_Selected" Value="1"/>
            </Trigger>
            <Trigger Property="SortingState" Value="Descending">
                <Setter Property="Foreground" Value="Black"/>
                <Setter Property="Opacity" TargetName="PART_SortIndicator" Value="1"/>
                <Setter Property="LayoutTransform" TargetName="PART_SortIndicator">
                    <Setter.Value>
                        <ScaleTransform ScaleY="-1" ScaleX="1"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="Opacity" TargetName="GridViewHeaderCell_Selected" Value="1"/>
            </Trigger>
            <Trigger Property="SortingState" Value="None">
                <Setter Property="Opacity" TargetName="PART_SortIndicator" Value="0"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            ToolTip="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:GridViewHeaderCell}}, Path=ActualWidth}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>