Binding an ObservableCollection.Count to Label with WPF -
i have simple label should include bound .count value of property of observablecollection.
the thing is, result 0 (zero). same property bound datagrid, works , updates if has changed in collection.
what doing wrong here?
here code:
<label contentstringformat="members: {0}"> <label.content> <binding path="memberslist.count" mode="oneway" updatesourcetrigger="default" /> </label.content> </label> the property looks like:
public static observablecollection<mitglied> memberslist { get; set; }
you can try this...
mainwindow.xaml.cs->
int counter = 0; private static observablecollection<string> _memberlist = new observablecollection<string>(); // suppose of string type..i took of string type check case public static observablecollection<string> memberlist { { return mainwindow._memberlist; } set { mainwindow._memberlist = value; } } mainwindow() { initializecomponent(); memberlist.add("0"); memberlist.add("1"); memberlist.add("2"); label1.datacontext = this; } private void button_click(object sender, routedeventargs e) { try { memberlist.removeat(counter); counter++; } catch(exception ex) { string strtemp=ex.message(); } } mainwindow.xaml->
<grid> <label name="label1" contentstringformat="members: {0}" margin="0,56,141,38" rendertransformorigin="0.158,1.154" horizontalalignment="right" width="183"> <label.content> <binding path="memberlist.count" mode="oneway" updatesourcetrigger="default"/> </label.content> </label> <button click="button_click" width="100" height="20" content="click" margin="43,169,360,122" /> </grid>
Comments
Post a Comment