更新数据绑定列表框 [英] Update a data bound list box

查看:55
本文介绍了更新数据绑定列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码在选中/取消选中复选框时触发。该复选框将用于缩小数据绑定的列表框。数据中的一个项目是指向png图像的链接,该图像在应用程序首次初始化时正确显示。在下面的代码中,我得到一个初始化'System.Windows.Media.Imaging.BitmapImage'每次都抛出异常例外。

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.

    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



我原本以为lstjobs.items.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?

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



xml元素格式为 image\GUID.png ,因此需要添加完整路径运行时。



我最初将此作为问题进行了探讨,并将XML更改为包含完整路径并注释了在属性中添加完整路径的需要,但是这产生了相同的结果。


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.

推荐答案

替换它:

Replace this:
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:



with:

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 ;)


这篇关于更新数据绑定列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆