定义DataGridTextColumn样式的工具提示

时间:2018-08-05 07:06:11

标签: wpf tooltip wpf-controls

我正在尝试更改DataGridTextColumn工具提示的样式,但是下面的xaml代码不起作用。当我运行该应用程序时,将显示自定义工具提示,并在其中编写System.Windows.Style。该按钮也未显示。我在哪里出错?

<DataGrid.Columns>
            <DataGridTextColumn  Width="*" Binding="{Binding W_NAME}" Header="Name">
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="ToolTip">
                            <Setter.Value>
                                <Style TargetType="ToolTip">
                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                    <Setter Property="HasDropShadow" Value="True"/>
                                    <Setter Property="HorizontalAlignment" Value="Left"/>
                                    <Setter Property="Content" Value="mytext"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToolTip">
                                                <Border Name="RootElement" CornerRadius="2,2,0,0">
                                                    <Border.Background>
                                                        <SolidColorBrush x:Name="BorderBrush" Color="Black"/>
                                                    </Border.Background>
                                                    <Grid Margin="4" Background="{TemplateBinding Background}">
                                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                                                          VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                                                          TextElement.FontFamily="{DynamicResource Glaho}"
                                                                          Content="{TemplateBinding Content}"
                                                                          Margin="4,5,4,4">

                                                        </ContentPresenter>
                                                        <Button Content="This is button" HorizontalAlignment="Right" Command="{Binding somecommand}"/>
                                                    </Grid>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>

1 个答案:

答案 0 :(得分:0)

您非常接近,问题在于您将$dt1 = date('d-m-Y H:i:s', strtotime($dt)); 设置为工具提示本身:

Style

您需要做的是将ToolTip控件设置为ToolTip,然后在其上设置样式:

<Style TargetType="DataGridCell">
    <Setter Property="ToolTip">
        <Setter.Value>
            <Style TargetType="ToolTip"> <-------------- badness!