2016-12-29 79 views
0

我有一個wpf c#應用程序。如何添加工具提示到datagrid單元格

我正在使用datagrid控件。

對於這些單元格之一,我想顯示多行工具提示。

這是我的代碼:

<DataGridTextColumn Header="{x:Static prop:Resources.Address}" Binding="{Binding Address}" > 
    <ToolTipService.ToolTip> 
     <StackPanel> 
      <TextBlock Text="Line#1" /> 
      <TextBlock Text="Line#2" /> 
     </StackPanel> 
    </ToolTipService.ToolTip> 
</DataGridTextColumn> 

但是當我運行這個沒有工具提示顯示?

回答

2

你可以使用CellStyle設置DataGridCell的工具提示屬性:

<DataGridTextColumn Header="{x:Static prop:Resources.Address}" Binding="{Binding Address}" > 
    <DataGridTextColumn.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Setter Property="ToolTip"> 
       <Setter.Value> 
        <ToolTip> 
         <StackPanel> 
          <TextBlock Text="Line#1" /> 
          <TextBlock Text="Line#2" /> 
         </StackPanel> 
        </ToolTip> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </DataGridTextColumn.CellStyle> 
</DataGridTextColumn> 
+0

感謝。我可以發誓我嘗試過。我一定錯過了一些東西。非常感謝 :) –

相關問題