0

Here is what I have so far:

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

and in XAML :

 <DataGridTemplateColumn Header="Image">
      <DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
                <Image Source="{Binding UserImage}" />
           </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>

and my save 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();

And database ofc : my results

But still it dont show any images in datagrid . Where is the problem guys?

Il Vic
  • 5,576
  • 4
  • 26
  • 37
Reza Pak
  • 129
  • 2
  • 9
  • Please add the code for *loading images to DataGrid* to question. – raidensan May 21 '18 at 11:30
  • i added that.do u know what is the problem ? – Reza Pak May 21 '18 at 12:29
  • see [this answer](https://stackoverflow.com/a/33214884/2928544) – raidensan May 21 '18 at 13:23
  • 1
    Provided that imgByteArr, i.e. what you read from the database, contains a valid encoded bitmap frame like a PNG or JPEG, just declare the UserImage property as byte array and pass imgByteArr to it. WPF will automatically perform the conversion to ImageSource. – Clemens May 21 '18 at 14:13
  • Can u give me the code? – Reza Pak May 21 '18 at 17:16
  • I don't have "the code". If you don't understand what it means to declare a byte array property that you bind to, you should probably start over and learn the basics. – Clemens May 21 '18 at 18:29

0 Answers0