这是我到目前为止所做的:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
FileDialog filedg = new OpenFileDialog();
filedg.Filter = "Images (*.jpg,*.png)|*.jpg;*.png|All Files(*.*)|*.*";
filedg.ShowDialog();
{
StrName = filedg.SafeFileName;
ImageName = filedg.FileName;
ImageSourceConverter isc = new ImageSourceConverter();
UserImage.SetValue(Image.SourceProperty, isc.ConvertFromString(ImageName));
}
filedg = null;
}
并在XAML中:
<DataGridTemplateColumn Header="Image">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding UserImage}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
和我的保存butten:
FileStream fsz = new FileStream(ImageName, FileMode.Open, FileAccess.Read);
byte[] imgByteArr = new byte[fsz.Length];
fsz.Read(imgByteArr, 0, Convert.ToInt32(fsz.Length));
fsz.Close();
database.Sp_gym(Username.Text.Trim(), UserFamily.Text.Trim(), UserTel.Text.Trim(), UserUsername.Text.Trim(),
UserPassword.Text.Trim(), Convert.ToByte(UserAge.Text.Trim()), 1, 1, UserCode.Text.Trim(), UserLocation.Text.Trim(), UserHomePhone.Text.Trim(),
UserDoreSine.Text.Trim(), UserBazu.Text.Trim(), UserKamar.Text.Trim(), UserGhad.Text.Trim(), UserVazn.Text.Trim(), 1, 1, 1, cAccCreditDate.SelectedDateTime.ToString(),
" " , UserCodePost.Text.Trim(), cAccCreditDate.SelectedDateTime.ToString() , UserCharge.Text.Trim() ,1, 1 , "" , imgByteArr);
database.SaveChanges();
和数据库ofc: my results
但它仍然没有在datagrid中显示任何图像。 问题在哪里?