windows - Simple Listbox Databinding in IronPython and WPF -
bear me, i'm new gui programming, ironpython, wpf , .net. however, familiar python. have read through many tutorials regarding databinding such devhawk these advanced me.
issue: i'd display in listbox control file paths python list can modified, add or remove entries. first part have accomplished following tutorials.
however, when update file list, listbox control not update new files , when attempt manipulate listbox app excepts following debug message vs2012:
add file click ['c:\test\employment_law_alert_03_28_2012.pdf', 'c:\test\graph paper .10in cartesian c-i-110.pdf', 'c:\test\greek alphabet symbol.pdf', 'c:\test\cnn money tipping guide - how tip.pdf']
traceback (most recent call last): file "", line 1, in systemerror: itemscontrol inconsistent items source. see inner exception more information.
obviously, listbox.itemsource out of sync python list. how 1 update two?
below sample codes...
python:
def addfile(self, sender, e): ... # files added self.fileinlist self.listboxpdfs.itemssource = self.fileinlist
xaml:
<listbox x:name="listboxpdfs" margin="2, 2, 2, 2"> <listbox.itemtemplate> <datatemplate> <textblock text="{binding bindsdirectlytosource=true}" /> </datatemplate> </listbox.itemtemplate> </listbox>
update: found 1 work around, surely there better way?
def addfile(self, sender, e): ... # files added self.fileinlist self.listboxpdfs.itemssource = [] # clear listbox first. self.listboxpdfs.itemssource = self.fileinlist # rebind.
if want listbox
update when new items added itemssource
collection, need use observablecollection<t>
. alternatively, can force update manually, slower, if there many items.
Comments
Post a Comment