I have been Bind the Image and other record in the Listview but i have problem in binding the record in DataGrid using linq to sql Please tell me how to bind the Image and first name in the DataGrid . I try to bind it but finally the result in my student table is null means no error but it show no record i am sure that i have some binding problem how can i solve it please please tell me and Thanks for reading . Here is My .xml file of wpf please see and correct the errors on this fill
<Window x:Class="UI.ViewStudent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UI"
Title="ViewStudent" Height="577" Width="415" xmlns:my="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit">
<Window.Resources >
<local:ImageDataConverter x:Key="ImageData1Converter"/>
</Window.Resources>
<Grid Height="540">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*" />
<ColumnDefinition Width="384*" />
</Grid.ColumnDefinitions>
<my:DataGrid ItemsSource="{Binding }" AutoGenerateColumns="False" Grid.Column="1" Margin="32,0,53,0" Name="dataGrid1" Height="200" VerticalAlignment="Top">
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="FirstName">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=FirstName}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTemplateColumn Header="Imagess">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Height="100" Source="{Binding Path= MyImage, Converter={StaticResource ImageData1Converter}}" />
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
</Grid >
</Window>
And for my .xml.cs file is
namespace UI
{
/// <summary>
/// Interaction logic for Pics.xaml
/// </summary>
public partial class Pics : Window
{
public Pics()
{
InitializeComponent();
}
private DataClasses1DataContext db = new DataClasses1DataContext();
private BindingListCollectionView CustomerView;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var custsInCA = from c in db.Students
where c.StudentID == 100
orderby c.LastName, c.FirstName
select c;
this.DataContext = custsInCA;
this.CustomerView = ((BindingListCollectionView)(CollectionViewSource.GetDefaultView(this.DataContext)));
}
//public string value { get; set; }
}
public class ImageDataConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
System.Data.Linq.Binary binaryData = value as System.Data.Linq.Binary;
//System.Data.Linq.Binary binaryData = value;// here there is the first error .How convert BinaryData to Object??
if (binaryData == null)
{
return null;
}
byte[] buffer = binaryData.ToArray();
if (buffer.Length == 0)
{
return null;
}
BitmapImage res = new BitmapImage();
res.BeginInit();
res.StreamSource = new System.IO.MemoryStream(buffer);
res.EndInit();
return res;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
My problem is that i bind the record in DataGrid in wrong way due to that i after compiling i show the Grid but having no record no picture please tell me what is wrong in my my app and how to solve fix it please tell me in completer example how to bind the Image and first name using linq to sql wpf
Check there is space after Path=