c# - Create UserControl WPF buttons for ListView -
i need buttons in list view. creating custom form scsm. list view working without problems, need add there add button, open button , delete button. add button working without problem, other buttons nothing. can me it?
thanks
xaml code here:
<listview name="listviewmonitor" verticalalignment="top" horizontalalignment="stretch" margin="10,0,00,0" minheight="100" grid.column="0" grid.row="1" itemssource="{binding path=customrelatedmonitor, updatesourcetrigger=propertychanged, mode=twoway}"> <listview.view> <gridview> <gridviewcolumn header="{binding path=strings[id].value, fallbackvalue=id, relativesource={relativesource findancestor, ancestortype={x:type views:formview}}}" displaymemberbinding="{binding path=id}" width="auto"/> <gridviewcolumn header="{binding path=strings[customassetstatus].value, fallbackvalue=customassetstatus, relativesource={relativesource findancestor, ancestortype={x:type views:formview}}}" width="auto"> <gridviewcolumn.celltemplate> <datatemplate> <smcontrols:listpicker name="listpickerassetstatus" horizontalalignment="stretch" width="auto" parentcategoryid="{binding source=12435943-eba1-3e78-bb6c-a731e44edcfd, mode=oneway}" selecteditem="{binding path=customassetstatus, mode=twoway, updatesourcetrigger=propertychanged}"/> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> </gridview> </listview.view> </listview> <stackpanel margin="10,0,10,0" grid.row="1" grid.column="1" verticalalignment="top" horizontalalignment="right"> <button verticalalignment="top" horizontalalignment="right" name="buttonaddmonitor" height="20" width="65" content="{binding path=strings[buttonadd].value, fallbackvalue=add, relativesource={relativesource findancestor, ancestortype={x:type views:formview}}}" click="buttonaddmonitor_click" /> <button verticalalignment="top" horizontalalignment="right" margin="0,10,0,0" name="buttonremovemonitor" height="20" width="65" isenabled="{binding elementname=listviewmonitor, path=selecteditems.count}" content="{binding path=strings[buttonremove].value, fallbackvalue=remove, relativesource={relativesource findancestor, ancestortype={x:type views:formview}}}" click="buttonremovemonitor_click" /> <button verticalalignment="top" horizontalalignment="right" margin="0,10,0,0" name="buttonopenmonitor" height="20" width="65" isenabled="{binding elementname=listviewmonitor, path=selecteditems.count}" content="{binding path=strings[buttonopen].value, fallbackvalue=open, relativesource={relativesource findancestor, ancestortype={x:type views:formview}}}" click="buttonopenmonitor_click" /> </stackpanel>
code buttons:
public listview listviewallmonitors { get; set; } private listview getlistview (string name) { switch (name) { case "buttonaddmonitor": case "buttonremovemonitor": case "buttonopenmonitor": { return this.listviewallmonitors; } default: { throw new exception(string.format("listview control: {0}- not found", name)); } } } private void buttonaddmonitor_click(object sender, routedeventargs e) { buttonadd_click(new guid("dd3bdb96-bc9e-d46e-5847-bab387039b36"), listviewmonitor); } private void buttonadd_click(guid mpclassguid, itemscontrol listview) { formutilities.instance.launchaddinstancepickerdialog(listview.itemssource collection<idataitem>, mpclassguid); } private void buttonremovemonitor_click(object sender, routedeventargs e) { var button = (button)sender; var customlistview = getlistview(button.name); if (customlistview == null) return; var list = (ilist<idataitem>)customlistview.itemssource; if (list == null) return; foreach (idataitem item in new arraylist(customlistview.selecteditems)) { list.remove(item); } } private void buttonopenmonitor_click(object sender, routedeventargs e) { var button = (button)sender; var listview = getlistview(button.name); if (listview == null) return; openinstance(listview); } public void openinstance(listview listview) { if (listview == null) return; foreach (idataitem dataitem in listview.selecteditems) { formutilities.instance.popoutform(dataitem); } }
Comments
Post a Comment