SQL Binary Image Data to DataGrid

Ok, I think I am close.  Having an issue with

 <Window.Resources>
        <local:BinaryToColorConverter x:Key="Tester"/>
    </Window.Resources>
Says an assembly isn't included.

Here is my full xaml:
<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:WpfTest"
        Title="MainWindow1" Height="300" Width="600" >

    <Window.Resources>
        <local:BinaryToColorConverter x:Key="Tester"/>
    </Window.Resources>

    <Grid x:Name="myGrid">
        <DataGrid x:Name="myDataGrid" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Value" Binding="{Binding Value}">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Background" Value="{Binding Path=rejPart., Converter={StaticResource Tester}}" />
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

Open in new window


Here is my codebehind.  

Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Imports WpfTest.BinaryToColorConverter


Namespace WpfTest
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()


            Dim CmdString As String = String.Empty
            Using con As New SqlConnection("Data Source=M2080855\SQLEXPRESS;Initial Catalog=qualityAlerts2013;Integrated Security=True")
                CmdString = "SELECT rejPart FROM qualityAlerts"
                Dim cmd As New SqlCommand(CmdString, con)
                Dim sda As New SqlDataAdapter(cmd)
                Dim dt As New DataTable("Employee")

                sda.Fill(dt)
                myDataGrid.ItemsSource = dt.DefaultView
            End Using
            myDataGrid.SelectedItem = Nothing
        End Sub
    End Class
   


Public Class BinaryToColorConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object,
                            ByVal targetType As System.Type,
                            ByVal parameter As Object,
                            ByVal culture As System.Globalization.CultureInfo) _
             As Object Implements System.Windows.Data.IValueConverter.Convert
        If value IsNot Nothing AndAlso TypeOf value Is Byte() Then
            Dim ByteArray As Byte() = TryCast(value, Byte())
            Dim bmp As New BitmapImage()
            bmp.BeginInit()
            bmp.StreamSource = New MemoryStream(ByteArray)
            bmp.EndInit()
            Return bmp
        End If
        Return Nothing
    End Function
    Public Function ConvertBack(ByVal value As Object,
                                ByVal targetType As System.Type,
                                ByVal parameter As Object,
                                ByVal culture As System.Globalization.CultureInfo) _
            As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New Exception("The method or operation is not implemented.")
        Return Nothing
    End Function


End Class
End Namespace

Open in new window


Ok, so what am I doing wrong here.  Any help is appreciated.
LVL 1
G ScottAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

G ScottAuthor Commented:
Ok, update my xaml and it now launches:

<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:WpfTest.WpfTest"
        Title="MainWindow1" Height="300" Width="600" >

    <Window.Resources>
        <local:BinaryToColorConverter x:Key="Tester"/>
    </Window.Resources>

    <Grid x:Name="myGrid">
        <DataGrid x:Name="myDataGrid" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Value" Binding="{Binding rejPart}">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Background" Value="{Binding Path=rejPart., Converter={StaticResource Tester}}" />
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

Open in new window


But looks like this:
9-6-2013-9-45-23-PM.jpg
0
Dave BaldwinFixer of ProblemsCommented:
What do you think it should look like?
0
G ScottAuthor Commented:
Like This
I got it.

<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:WpfTest.WpfTest"
        Title="MainWindow1" Height="300" Width="600" >

    <Window.Resources>
        <local:BinaryToColorConverter x:Key="Convert"/>
    </Window.Resources>

    <Grid x:Name="myGrid">
        <DataGrid x:Name="myDataGrid" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="Value" Binding="{Binding alertNumber}"></DataGridTextColumn>
                
                <DataGridTemplateColumn Width="Auto" Header="Image" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Width="150" Margin="5" Source="{Binding rejPart, Converter={StaticResource Convert}}" ></Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <!--<DataGridTextColumn Header="Value" Binding="{Binding rejPart}">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Background" Value="{Binding Image, Converter={StaticResource Tester}}" />
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>-->
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

Open in new window


 Binding="{Binding rejPart}"  was the offending line.  rejPart is my database field name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
G ScottAuthor Commented:
I figured it out on my own.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.