2017-03-03 31 views
0

我將圖片路徑保存到datagrid行,並且我想在鼠標懸停在datagrid行上時顯示彈出圖像。DataGrid Popup圖像

像這樣:

example

這是我的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 

    } 

的prolem是,我不知道如何我可以做嗎。工具提示或彈出?語法是什麼?

感謝和抱歉我的英語不好。

<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> 

回答

0

工具提示DataGridCell將是可見的。

<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> 
+0

謝謝!!!我正在考慮這個! – Haldyr

0

可以使用IsMouseOver屬性來確定鼠標在一個對象和一個MultiDataTrigger評估多個條件:當光標位於列的單元