在DataGridTextColumn上添加工具提示

时间:2014-09-29 09:21:57

标签: c# wpf xaml datagrid datagridtextcolumn

我有一个带有一些DataGridTextColumn的DataGrid,如下所示:

<DataGrid x:Name="DonneesBrutes" IsReadOnly="True" ItemsSource="{Binding Path=ResultatCollectionGrande}" Margin="10,65,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected">
    <DataGrid.Columns>
        <DataGridTextColumn x:Name="PrisEnCompte" Binding="{Binding Path=Flag}" Header="Pris En Compte"></DataGridTextColumn>
        <DataGridTextColumn x:Name="PMRQ" Width="*" Binding="{Binding Path=Pmid}" Header="PMID"></DataGridTextColumn>
        <DataGridTextColumn x:Name="Ligne" Width="40" Binding="{Binding Path=Ligne}" Header="Ligne" IsReadOnly="True"></DataGridTextColumn>
        <DataGridTextColumn x:Name="LibellePMRQ" Width="*" Binding="{Binding Path=LibellePmrq}" Header="Libellé PMRQ">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="ToolTip"
        Value="{Binding RelativeSource={RelativeSource Self},
                        Path=Column.(ToolTipService.ToolTip)}"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn x:Name="OTM" Width="*" Binding="{Binding Path=Otm}" Header="OTM"></DataGridTextColumn>
        <DataGridTextColumn x:Name="TOTM" Width="50" Binding="{Binding Path=Totm}" Header="TOTM"></DataGridTextColumn>
        <DataGridTextColumn x:Name="LibelleTOTM" Width="*" Binding="{Binding Path=LibelleTotm}" Header="Libellé TOTM">
            <DataGridTextColumn.HeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="ToolTip"
        Value="{Binding RelativeSource={RelativeSource Self},
                        Path=Column.(ToolTipService.ToolTip)}"/>
                </Style>
            </DataGridTextColumn.HeaderStyle>
        </DataGridTextColumn>
        <DataGridTextColumn x:Name="GA" Width="70" Binding="{Binding Path=GroupeAlerte}" Header="GA"></DataGridTextColumn>
        <DataGridTextColumn x:Name="Discipline" Width="120" Binding="{Binding Path=Discipline}" Header="Discipline"></DataGridTextColumn>
        <DataGridTextColumn x:Name="DisciplineSubstituee" Width="120" Binding="{Binding Path=DisciplineSubstituee}" Header="Discipline Substituée"></DataGridTextColumn>
        <DataGridTextColumn x:Name="Remarque" Width="*" Binding="{Binding Path=.Remarque}" Header="Remarque"></DataGridTextColumn>

    </DataGrid.Columns>
</DataGrid>

我想在鼠标悬停在DataGridTextColumn LibelleTOTM上时创建一个弹出窗口。为此,我做了:

<DataGridTextColumn x:Name="LibelleTOTM" Width="*" Binding="{Binding Path=LibelleTotm}" Header="Libellé TOTM">
    <DataGridTextColumn.HeaderStyle>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="ToolTip"
                    Value="{Binding RelativeSource={RelativeSource Self},Path=Column.(ToolTipService.ToolTip)}"/>
        </Style>
    </DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>

我在互联网上找到了这个解决方案,但它对我的解决方案不起作用。我已经适应了我的情况,但可能还不够......当鼠标在LibelleTOTM上时,没有任何反应。是TargetType错了,我不能这样绑定自己吗?我想打开一个带有DataGridTextColumn值的弹出窗口,因此在ToolTip中发送我Binding="{Binding Path=LibelleTotm}"上的<DataGridTextColumn x:Name="LibelleTOTM" Width="*" Binding="{Binding Path=LibelleTotm}" Header="Libellé TOTM">

如果有人知道那里缺少什么,那有什么不对,我应该怎么做呢?

提前致谢。

弗洛。

1 个答案:

答案 0 :(得分:4)

HeaderStyle应用于列标题。除非我在你的问题中遗漏了某些内容,否则你需要像这样定位DataGridCell本身。

<DataGridTextColumn.CellStyle>
    <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
          <Setter Property="ToolTip" Value="{Binding Del_Date, StringFormat=MM/dd/yyyy HH:mm}" />
    </Style>
</DataGridTextColumn.CellStyle>