c# - binding windows 8 textBlock in MVVM light -
i 'm having problem textblock/textbox binding. textblock doesn't display property's content. when 'm debugging app, property has content. how can it? xaml.
<textblock horizontalalignment="left" margin="730,191,0,0" textwrapping="wrap" text="{binding xmlcontentfile, mode=twoway}" verticalalignment="top" height="429" width="465"/>
i finding simple code in web, didn't find code.
code property
public string xmlcontentfile { { homecoming this.xmlcontentfile; } set { this.xmlcontentfile = value; } }
my datacontext
datacontext="{binding main, source={staticresource locator}}">
method load xml file string variable
public async void xmlcontentload() { if (selectfile != null) { seek { storagefolder storagefolder = applicationdata.current.localfolder; storagefile storagefile = await storagefolder.getfileasync(selectfile); xmlfiletextcontent = await fileio.readtextasync(storagefile); } grab (exception) { throw new exception("bug"); } } }
the problem xmlcontentfile property doesn't raise notifications when it's changed. viewmodel needs implement inotifypropertychanged , raise event whenever property has changed.
it's view , info bindings getting setup , executed before xmlcontentload completes (it's asynchronous). if binding has completed before info loaded, way binding happen 1 time again if property raises notification has changed.
it's worth pointing out in xmlcontentload method you're setting private variable , not public property.
xmlfiletextcontent = await fileio.readtextasync(storagefile);
setting private variable never raise property alter notification if have setter code wired raise notification. you'll either need alter xmlcontentload set property , have onpropertychanged notification in setter (recommended) or you'll need phone call onpropertychanged after set private variable (not recommended).
hope helps.
dev support, design back upwards , more awesome goodness on way: http://bit.ly/winappsupport
c# xaml windows-8 mvvm-light
No comments:
Post a Comment