DataGrid 弹出图像

DataGrid Popup image

我将图片路径保存到数据网格行,我想在鼠标悬停在数据网格行上时显示弹出图像。

像这样:

这是我的 xaml 代码:

            <DataGrid Name="DG_selected_pictures" AutoGenerateColumns="False"  Margin="8,74,8,-113.8" IsReadOnly="True">
                <DataGrid.Columns >
                    <DataGridTextColumn Binding="{Binding Path=Picture}" MinWidth="485"   />
                </DataGrid.Columns>
            </DataGrid>

C#代码背后:

        private void BT_select_pictures_click(object sender, RoutedEventArgs e) 
    {
        var picture_list = new ObservableCollection<DataObject>();
        Microsoft.Win32.OpenFileDialog openfile = new Microsoft.Win32.OpenFileDialog();
        //string filter = "Picture files "(*.jpg)|*.jpg|All files (*.*)|*.*";
        openfile.Filter = "Picture files (*.jpg)|*.jpg|All files (*.*)|*.*";
        openfile.Multiselect = true;

        if (openfile.ShowDialog() == true)
        {
            int index = openfile.FileName.LastIndexOf("\") + 1;
            int lastindex = openfile.FileName.Length - 1;
            string folderPath = openfile.FileName;
            folderPath = folderPath.Remove(index, folderPath.Length - index);
            TB_selected_files_folder.Text = folderPath;
        }
        foreach (String picture in openfile.FileNames)
        {
            i++;
            picture_list.Add(new DataObject() { Picture = picture });
            selected_pictures.Add(picture);
        }
        LB_selected_pictures_count.Content = Convert.ToString(i) + " db";

        this.DG_selected_pictures.ItemsSource = picture_list; // This is the datagrid

    }

问题是我不知道该怎么做。工具提示还是弹出?语法是什么?

谢谢,抱歉我的英语不好。

当光标位于列单元格上时,DataGridCell 的工具提示将可见:

<DataGridTextColumn Binding="{Binding Path=Picture}" MinWidth="485">
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <Image Source="{Binding Path=Picture}"/>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

您可以使用 IsMouseOver 属性 来确定鼠标是否在对象上,并使用 MultiDataTrigger 来评估多个条件。

<Style TargetType="Image">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
                <Condition Binding="{Binding Picture, Converter={StaticResource IsImageNullConverter}}" Value="False" />
            </MultiDataTrigger.Conditions>

        </MultiDataTrigger>
    </Style.Triggers>
</Style>