Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a section of code that fires when a check box is checked/unchecked. The check box is going to be used to narrow down a listbox that is data bound. One item in the data is a link to an png image which shows correctly when the application first initializes. In the code below, I get a "Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception" exception every time.
VB
    Private Sub chkShowCurrent_Click(sender As Object, e As RoutedEventArgs) Handles chkShowCurrent.Click
    Dim o As ObjectDataProvider
    Dim xDoc = XDocument.Load(sFileName)

    If chkShowCurrent.IsChecked = False Then
        'MsgBox("false")
    End If

    If chkShowCurrent.IsChecked = True Then
        'MsgBox("true")
        Dim OnlyCurrent = From job In xDoc.Root.Descendants("Job")
                          Where job.Element("Status").Value = "a-current"
                          Order By job.Element("Status").Value, job.Element("Rush").Value, Convert.ToDateTime(job.Element("DateOut").Value)
                          Select job

        lstJobs.ItemsSource = OnlyCurrent

    End If
    lstJobs.Items.Refresh()
    o = FindResource("jobs")
    o.Refresh()
End Sub

I had originally thought that the lstjobs.items.refresh was the issue, but the exception doesn't popup until after End Sub has been reached. I have tried adding a breakpoint to the code at the checkbox code and step through the code, but the answer still eludes me. Can anyone tell me where my error is?
VB
Public Property Artwork() As String
Get
    Return _Artwork
End Get
Set(ByVal value As String)
    If value = String.Empty Then value = "images\Untitled.png"

    If My.Computer.FileSystem.FileExists("\\ARTSTATION\Users\Public\XML Job Board\" & value) Then
        value = "\\ARTSTATION\Users\Public\XML Job Board\" & value
    Else
        value = "\\ARTSTATION\Users\Public\XML Job Board\images\Untitled.png"
    End If
    _Artwork = value
End Set

The xml element is formated as image\GUID.png, thus necessitating the need to add the full path at runtime.

I had originally explored this as the issue and changed the XML to contain the full path and commented out the need for adding the full path in the properties, but this yielded the same results.
Posted
Updated 1-Jun-15 1:57am
v2
Comments
gggustafson 1-Jun-15 17:54pm    
If VB is like C# then before lstJobs.ItemsSource = OnlyCurrent you need lstJobs.ItemsSource = null (or whatever in VB)
Sean Donnahoe 2-Jun-15 11:51am    
I didn't even think of that. I'll give that a try. It's always the little things that elude us. Thanks.
Sean Donnahoe 2-Jun-15 11:58am    
Unfortunately, that did not work.

1 solution

Replace this:
VB
If chkShowCurrent.IsChecked = True Then
    'MsgBox("true")
    Dim OnlyCurrent = From job In xDoc.Root.Descendants("Job")
                      Where job.Element("Status").Value = "a-current"
                      Order By job.Element("Status").Value, job.Element("Rush").Value, Convert.ToDateTime(job.Element("DateOut").Value)
                      Select job

    lstJobs.ItemsSource = OnlyCurrent

End If


with:
VB
If chkShowCurrent.IsChecked Then
    'MsgBox("true")
    Dim OnlyCurrent = (From job In xDoc.Root.Descendants("Job")
                      Where job.Element("Status").Value = "a-current"
                      Order By job.Element("Status").Value, job.Element("Rush").Value, Convert.ToDateTime(job.Element("DateOut").Value)
                      Select job).ToList()

    lstJobs.ItemsSource = OnlyCurrent

End If


It should resolve your issue. If not, please notify me ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900