我看到了一些SO的问题,但我似乎不知道如何在我目前的设置中做到这一点。
我的Datagrid包含这样的内容。
CellStyle="{StaticResource DataGridContentCellCentering}"
<Style x:Key="DataGridContentCellCentering" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{StaticResource PColour}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
<ContentPresenter HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{StaticResource PColour}"/>
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
<Setter Property="MinHeight" Value="15"/>
</Style>
我的数据表格中有一个DataGridTextColumn。
<DataGridTextColumn Header="{x:Static p:Resources.Sabel}" MinWidth="120"
x:Name="SName" Binding="{Binding SName}" Width="*"
EditingElementStyle="{StaticResource dataGridTextColumnLimit}"/>
我的 dataGridTextColumnLimit
是这样的,我想以某种方式有一个工具提示,当我把鼠标悬停在单元格上时,显示文本框的文本内容。
<Style x:Key="dataGridTextColumnLimit" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="{StaticResource Balour}"/>
<Setter Property="MaxLength" Value="20"/>
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="TextAlignment" Value="Center"/>
</Style>
我想以某种方式有一个工具提示 当我把鼠标悬停在单元格上时,它就会显示文本框的文本内容。这可能容易做到吗?
谢谢你
只要将工具提示属性绑定到单元格的数据上下文即可。
<Style x:Key="DataGridContentCellCentering" TargetType="{x:Type DataGridCell}">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self},Path=DataContext}"/>
<Setter Property="Background" Value="{StaticResource PColour}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
<ContentPresenter HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{StaticResource PColour}"/>
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
<Setter Property="MinHeight" Value="15"/>
</Style>