Q061. XamDataGrid で別の列の値をツールチップで表示するには?

A. CellValuePresenter のスタイルを設定します。以下のサンプルのように、XAML 内で自身のレコードのセルを参照することができます。でも XAML 内で添字も使えたんですね。初めて知った時はかなり驚きました。

<Window x:Class="MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:igDP="http://infragistics.com/DataPresenter"
  Title="MainWindow" Height="350" Width="525" >
  <Window.Resources>
    <Style TargetType="{x:Type igDP:CellValuePresenter}">
      <Setter Property="ToolTip" 
        Value="{Binding RelativeSource={x:Static RelativeSource.Self}, 
        Path=Record.Cells[3].Value}" />
    </Style>
  </Window.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50" />
      <RowDefinition />
    </Grid.RowDefinitions>
    <igDP:XamDataGrid Grid.Row="1" BindToSampleData="True" />
  </Grid>
</Window>



WPF FAQ の目次に戻る