my image converter class
- public sealed class ImageConverter : IValueConverter
- {
- public BitmapImage ConvertByteArrayToBitMapImage(byte[] imageByteArray)
- {
- if (imageByteArray == null) return null;
- var byteBlob = imageByteArray as byte[];
- var ms = new MemoryStream(byteBlob);
- var bmi = new BitmapImage();
- bmi.StreamSource = ms;
- return bmi;
- }
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- BitmapImage img = new BitmapImage();
- if (value != null)
- {
- img = this.ConvertByteArrayToBitMapImage(value as byte[]);
- }
- return img;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return null;
- }
- }
databinding logic
- string connection = ConfigurationManager.ConnectionStrings["POSconnection"].ConnectionString;
- SqlConnection con = new SqlConnection(connection);
- SqlCommand cmd = new SqlCommand("SP_Getsubitem", con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@getname", "SALADS");
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- DataSet ds = new DataSet();
- da.Fill(dt);
- getdatas.ItemsSource = dt.DefaultView;
mylistview code in xaml
- <ListView x:Name="getdatas" ItemsSource="{Binding}" Margin="-407,-270,47,120.2"
- Grid.RowSpan="2">
- <ListView.ItemContainerStyle>
- <Style TargetType="ListViewItem">
- <Setter Property="BorderThickness" Value="5"/>
- <Setter Property="Margin" Value="10"/>
- <Setter Property="Padding" Value="10"/>
- Style>
- ListView.ItemContainerStyle>
- <ListView.ItemTemplate>
- <DataTemplate>
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="{Binding price}" />
- <Image Height="300" Width="300" Source="{Binding ImageFile,
- Converter={StaticResource ImageConverter}}" />
- <TextBlock Text="{Binding ImageFile}" />
- StackPanel>
- DataTemplate>
- ListView.ItemTemplate>
- <ListBox.ItemsPanel>
- <ItemsPanelTemplate>
- <UniformGrid Columns="5" HorizontalAlignment="Stretch"/>
- ItemsPanelTemplate>
- ListBox.ItemsPanel>
- ListView>
R sowmyaPosted Mar 6, 2019, 12:45 AM
Salman BegPosted Mar 6, 2019, 12:32 AM