将鼠标悬停在datagrid上时在工具提示中显示sql图像 [英] Display sql image in tooltip when mouseover datagrid
本文介绍了将鼠标悬停在datagrid上时在工具提示中显示sql图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
当鼠标悬停在datagrid上时如何在工具提示中显示sql图像.此代码不起作用.
Hi everyone,
How can i display sql image in tooltip when mouseover datagrid.I have this code that do not work.
<DataGridTemplateColumn Header="Image" Width="45" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="2" Padding="2">
<Image Source="{Binding Path=Picture}" Width="120" Height="50">
<Image.ToolTip>
<ToolTip DataContext="{Binding Path=Picture, ElementName=grdPersonnel1}" BorderBrush="LightBlue">
</ToolTip>
</Image.ToolTip>
</Image>
</Border>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
推荐答案
我将图片保存在sql数据库中,我可以在datagrid中检索并查看它,但是我想将鼠标悬停在图片上,工具提示显示它更大(缩放).
此代码块在工具提示中显示此消息:Byte [] Array.
I saved a picture in sql databse, and i can retrieve and see it in datagrid but i want to do mouse over on picture, tooltip display it more larger (zoom).
This code block has this message in tooltip:Byte[] Array.
<DataGridTemplateColumn Header="Image" Width="45" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Image Source="{Binding Path=Picture}" Width="100" Height="50" Stretch="Uniform" ToolTip="{Binding Path=Picture}">
</Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
添加新的记录事件:
Add new record event:
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.* ";
dlg.ShowDialog();
FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
System.IO.Stream stream = System.IO.File.Open(dlg.FileName, System.IO.FileMode.Open);
BitmapImage imgsrc = new BitmapImage();
imgsrc.BeginInit();
imgsrc.StreamSource = stream;
imgsrc.EndInit();
this.Picture.Source = imgsrc;
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\programing\WPF\DataBase.mdf;Integrated Security=True;User Instance=True";
con.Open();
SqlCommand sc = new SqlCommand("Insert Into Personnels(No,Name,Family,Picture) Values(@No,@Name,@Family,@Tozihat,@Picture)", con);
sc.Parameters.AddWithValue("@No", txtNo.Text);
sc.Parameters.AddWithValue("@Name", txtName.Text);
sc.Parameters.AddWithValue("@Family", txtFamily.Text);
sc.Parameters.AddWithValue("@Picture", data);
sc.ExecuteNonQuery();
con.Close();
}
我希望这会对您有所帮助.
I hope this will help you.
<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>]]>
这篇关于将鼠标悬停在datagrid上时在工具提示中显示sql图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文