1

我想显示DataGridComboBoxColumn的元素样式(非编辑模式)的工具提示。我一直无法想出一个好的方法来做到这一点。在下面的示例中,我可以显示工具提示,或者通过将IsHitTestVisible属性更改为 true 或 false 来允许对单元格进行编辑。我无法在不编辑时显示工具提示并允许启动编辑模式。当命中测试为真时,工具提示有效。当命中测试为假时,组合框将下拉。

获得编辑和工具提示的最佳方式是什么?

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <DataGrid ItemsSource="{Binding}"
              AutoGenerateColumns="False"
              >
        <DataGrid.Columns>
            <DataGridComboBoxColumn Header="Yo">
                <DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ComboBox">
                                        <TextBlock 
                                            Text="{TemplateBinding Text}"
                                            IsHitTestVisible="False"
                                            ToolTip="Yo"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGridComboBoxColumn.ElementStyle>
            </DataGridComboBoxColumn>
        </DataGrid.Columns>
    </DataGrid>
</Grid>
</Window>



using System;
using System.Collections.Generic;
using System.Windows;

namespace WpfApplication2
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new List<string> { "Hello" };
    }
  }
}
4

1 回答 1

0

尝试使用 DataGridTemplateColumn 并将 IsReadOnly="false" 添加到 DataGrid

...

<dg:DataGrid.Columns >
    <dg:DataGridTemplateColumn >
        <dg:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding something}">
                    <ToolTip Content="Write something here" />
                 </TextBlock>
             </DataTemplate>
         </dg:DataGridTemplateColumn.CellTemplate>
    </dg:DataGridTemplateColumn>
<dg:DataGrid.Columns >

...
于 2011-08-21T07:26:32.177 回答