Hi,
i'm trying to populate my XamDataGrid with pictures stored from a database(SqlServer) and the datatype is "varbinary(MAX)" ,but till now i cannot work out this operation.
I use a Converter as follow:
public class ImageDataConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { byte[] image = ((System.Data.Linq.Binary)value).ToArray(); return image; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotSupportedException(); } }
to convert Byte and in my Xaml i use this one:
<Grid> <Grid.Resources> <local:ImageDataConverter x:Key="imageConverter"/> <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="Picture"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"> <Image Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
</Grid.Resources> <igDP:XamDataGrid x:Name="XamDataGrid1" Theme="Office2k7Black" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Converter="{StaticResource imageConverter}" Name="Pic" Label="Pic"> <igDP:Field.Settings> <igDP:FieldSettings CellMinWidth="100" CellMaxHeight="100" CellMinHeight="100" CellMaxWidth="100" CellWidth="100" CellValuePresenterStyle="{StaticResource Picture}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="ID" Label="ID"></igDP:Field> <igDP:Field Name="Note" Label="Note"></igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid>
in the code behind instead:
private DataClasses1DataContext dc; public DataGridShow() { InitializeComponent(); dc = new DataClasses1DataContext(); var query = from c in dc.Tabolos select new {c.Pic, c.ID, c.Note}; this.XamDataGrid1.DataContext = query.ToList(); dc.SubmitChanges(); }...
when i debug i receive an error in this line of the Converter Class:
byte[] image = ((System.Data.Linq.Binary)value).ToArray(); //Object reference not set to an instance of an object.
Do you know how i can work out this feature ,or can you help me where i wrong?
Thanks so much for your attention.
Have a happy time.
Hi Mr.Alex,
yes that'spost is so usefull,
I create a new conveter so i can populate my XamGrid with the pictures stored from the Datadbase.
Thanks so much for your help.
Have a good work
Cheers..
Hello,
For loading images from SQL server, you can look at this forum thread:
http://community.infragistics.com/forums/t/23532.aspx
Hope this helps,
Alex.