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>
여기에서 찾은 솔루션 : WPF DataGrid와 함께 5 개의 무작위 gotchas
DataGridTextColumn은 보이지 않습니다. 헤더 또는 컨텐츠에서 툴팁을 설정해야합니다.
헤더에서 툴팁을 설정하려면 헤더를 텍스트 블록으로 변경하십시오.
<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>
도구 립 서비스를 설정합니다.
<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>
씨#:
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