我将图片路径保存到数据网格行,当鼠标悬停在数据网格行上时,我想显示弹出图像。
像这样:
这是我的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
}
问题是,我不知道我该怎么做。工具提示还是弹出?什么是语法?
谢谢,抱歉我的英语不好。
答案 0 :(得分:0)
当光标位于列单元格上时,DataGridCell的ToolTip将可见:
<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>
答案 1 :(得分:0)
您可以使用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>