c# - ListView two way compiled binding (x:Bind) -
i want display several names, , want them editable. used observablecolection, , bind listview new x:bind feature.
here's xaml:
<listview> <listview itemssource="{x:bind viewmodel.players}"> <listview.itemcontainerstyle> <style targettype="listviewitem"> <setter property="horizontalcontentalignment" value="stretch" /> </style> </listview.itemcontainerstyle> <listview.itemtemplate> <datatemplate xmlns:model="using:flechette.model" x:datatype="model:player"> <textbox text="{x:bind name, mode=twoway}" /> </datatemplate> </listview.itemtemplate> </listview>
and code behind:
public sealed partial class gamesettingspage : page { viewmodel.gamesettingsviewmodel viewmodel { get; set; } public gamesettingspage() { initializecomponent(); datacontextchanged += (s, e) => viewmodel = datacontext viewmodel.gamesettingsviewmodel; } }
the problem twoway binding failed compile, error cs1061 'weakreference' not contain definition 'lostfocus' , no extension method 'lostfocus' accepting first argument of type 'weakreference' found (are missing using directive or assembly reference?)
how can fix ?
this seems problem in preview version of windows 10 sdk. given following code:
mainpage.xaml:
<listview x:name="players"> <listview.itemcontainerstyle> <style targettype="listviewitem"> <setter property="horizontalcontentalignment" value="stretch" /> </style> </listview.itemcontainerstyle> <listview.itemtemplate> <datatemplate x:datatype="local:player"> <textbox text="{x:bind name, mode=twoway}" /> </datatemplate> </listview.itemtemplate> </listview>
mainpage.xaml.cs:
private observablecollection<player> players = new observablecollection<player>(); public mainpage() { this.initializecomponent(); } protected override void onnavigatedto(navigationeventargs e) { this.players.add(new player()); this.players.add(new player()); this.players.add(new player()); this.players.add(new player()); this.players.add(new player()); this.players.itemssource = players; }
player.cs:
public class player : inotifypropertychanged { private string name; public string name { { return name; } set { if (value == name) return; name = value; onpropertychanged(); } } public event propertychangedeventhandler propertychanged; [notifypropertychangedinvocator] protected virtual void onpropertychanged([callermembername] string propertyname = null) { propertychanged?.invoke(this, new propertychangedeventargs(propertyname)); } }
the compilation , app works , provides expected behavior:
Comments
Post a Comment