c# - Why the ItemsControl doesn't show all -
i have itemscontrol.
<dockpanel height="280"> <border cornerradius="6" borderbrush="gray" background="lightgray" borderthickness="2" > <scrollviewer verticalscrollbarvisibility="auto"> <itemscontrol height="400" name="ictodolist" itemssource="{binding items}"> <itemscontrol.itemtemplate> <datatemplate> <grid name="todolist"> <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <textblock text="{binding starttime, fallbackvalue=' '}" grid.row="0"/> <textblock text="{binding connectedtime, fallbackvalue=' '}" grid.row="1"/> <textblock text="{binding disconnectedtime, fallbackvalue=' '}" grid.row="2"/> <textblock text="{binding dialingresult, fallbackvalue=' '}" grid.row="3"/> </grid> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> </scrollviewer> </border> </dockpanel>
in mainviewmodel.cs, have:
public class mainviewmodel : notifyuibase public observablecollection<calls> items = new observablecollection<calls>(); public observablecollection<calls> items { { return items; } set { items = value; raisepropertychanged(); } }
and:
public class notifyuibase : inotifypropertychanged { // minimal implementation of inotifypropertychanged matching msdn // note dependent on .net 4.5+ because of callermembername public event propertychangedeventhandler propertychanged; public void raisepropertychanged([callermembername] string propertyname = "") { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } }
then in code behind: mainviewmodel _datacontext;
public mainwindow() { initializecomponent(); _datacontext = new mainviewmodel(); this.datacontext = _datacontext; dictionary<string, string> dict = new dictionary<string, string>(); dict = runscript(); calls c = new calls(); c.starttime = dict["starttime"]; c.connectedtime = dict["connectedtime"]; c.disconnectedtime = dict["disconnectedtime"]; c.dialingresult = dict["dialingresult"] + '\n'; dispatcher.begininvoke((action)delegate() { if (c != null) _datacontext.items.add(c); });
edit:
to add calls, used actionblock
in async task
method.
var actionblock = new actionblock<t>( t=> { dictionary<string, string> dict = new dictionary<string, string>(); dict = runscript(t); calls c = new calls(); // c dict dispatcher.begininvoke((action)delegate() { if (c != null) _datacontext.items.add(c); }); }, executiondataflowblockoptions); // link bufferblock actionblock await actionblock.completion;
suppose have 100 calls, expected output on screen should have 100 sets data. sure not null. displays 6 data sets, why?
finally, itemscontrol doesn't work scrollviewer, that's why not seeing items. removing scrollviewer element , add 1 control template of itemscontrol setting template property:
<dockpanel height="280"> <border cornerradius="6" borderbrush="gray" background="lightgray" borderthickness="2" > <itemscontrol name="ictodolist" itemssource="{binding items}"> <itemscontrol.itemtemplate> <datatemplate> <grid name="todolist"> <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <textblock text="{binding starttime, fallbackvalue=' '}" grid.row="0"/> <textblock text="{binding connectedtime, fallbackvalue=' '}" grid.row="1"/> <textblock text="{binding disconnectedtime, fallbackvalue=' '}" grid.row="2"/> <textblock text="{binding dialingresult, fallbackvalue=' '}" grid.row="3"/> </grid> </datatemplate> </itemscontrol.itemtemplate> <itemscontrol.template> <controltemplate> <scrollviewer x:name="scrollviewer" padding="{templatebinding padding}"> <itemspresenter /> </scrollviewer> </controltemplate> </itemscontrol.template> </itemscontrol> </border> </dockpanel>
Comments
Post a Comment