DataGridColumnのツールヒントを設定することができません。
-
20-09-2019 - |
質問
私は次のことを試してみました
<tk:DataGridTextColumn
Header="Item"
Binding="{Binding Item.Title}"
ToolTipService.ToolTip="{Binding Item.Description}" />
そして、私は、任意のツールチップが表示されません。
任意のアイデア? それも実装されていますか。
解決
これは私のために動作します:
<Style TargetType="{x:Type Custom:DataGridColumnHeader}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="ToolTip" Value="{Binding Column.(ToolTipService.ToolTip), RelativeSource={RelativeSource Self}}"/>
</Trigger>
</Style.Triggers>
</Style>
他のヒント
plsは、以下のコードは、あなたのために働くならば、それは、列ヘッダおよび細胞のためのツールチップを表示する必要があるセルのツールチップをチェックし、データオブジェクトの説明フィールドを曲げする必要があります:
<DataGridTextColumn Width="SizeToCells"
MinWidth="150"
Binding="{Binding Name}">
<DataGridTextColumn.Header>
<TextBlock Text="Name" ToolTipService.ToolTip="Header ToolTip" />
</DataGridTextColumn.Header>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="ToolTip" Value="{Binding Description}" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
ここで見つけるソリューション:<のhref = "http://blogs.msdn.com/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx" のrel = WPFのDataGridする
と> 5つのランダム落とし穴 "noreferrer"DataGridTextColumnは表示されません。あなたは、ヘッダーや内容にツールチップを設定する必要があります。
のTextBlockにヘッダを変更し、ヘッダにヒントを設定する
<tk:DataGridTextColumn
Binding="{Binding Item.Title}">
<tk:DataGridTextColumn.Header>
<TextBlock
Text="Text"
ToolTipService.ToolTip="Tooltip for header" />
</tk:DataGridTextColumn.Header>
</tk:DataGridTextColumn>
スタイルでそれを設定し、コラムの内容にツールヒントを設定するには:
<tk:DataGridTextColumn
Binding="{Binding Item.Title}"
Heading="Text">
<tk:DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="ToolTipService.ToolTip" Value="{Binding Item.Description}" />
</Style>
</tk:DataGridTextColumn.ElementStyle>
</tk:DataGridTextColumn>
またEditingElementStyle
を設定したい場合があります。
あなたのコラムではなくDataGridTextColumnのDataGridTemplateColumnがある場合はさらに、あなたはこのようにそれを行うことができます:
<DataGridTemplateColumn x:Name="MyCheckBoxColumn" CellStyle="{StaticResource MyCellStyle}" >
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="MyHeaderName" ToolTip="This is my column description" />
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox ... />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
ヘッダースタイルのSet ToolTipService.ToolTipプロパティます:
<Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>
ここでは、私がDataGridCheckBoxColumnの代わりに、テキストでイメージを持っていたとき、私はそれを使用する方法です。 XAMLます:
<Window x:Class="MyProject.GUI.ListDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModel="clr-MyProject.GUI.ViewModels"
Title="{Binding Title}" Height="350" Width="650"
MinHeight="350" MinWidth="650"
xmlns:res="clr-MyProject.GUI.Resources" Closing="Window_Closing" WindowStyle="ToolWindow">
<Window.Resources>
<BitmapImage x:Key="MyImageSource" UriSource="Resources/Images/SelectDeselect.png" />
<Style x:Key="CheckBoxHeader" TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Image Width="15" Height="15" Source="{StaticResource MyImageSource}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
のC#ます:
DataGridCheckBoxColumn checkColumn = new DataGridCheckBoxColumn();
checkColumn.HeaderStyle = new System.Windows.Style();
checkColumn.CanUserSort = checkColumn.CanUserResize = false;
checkColumn.Width = new DataGridLength(25);
checkColumn.HeaderStyle = (Style)Resources["CheckBoxHeader"];
checkColumn.CellStyle = (Style)Resources["CenterAlignedCellStyle"];
checkColumn.IsReadOnly = false;
dataGrid.Columns.Add(checkColumn);
所属していません StackOverflow