c# - How to enable button if item selected in a GridView -
i want enable button when grid view item selected update gui in metro apps. button include list view item. below code snippet of want do. please help.
<gridview name="searchpanelgrid" selectionmode="single" horizontalalignment="left" scrollviewer.ishorizontalscrollchainingenabled="true" scrollviewer.isverticalscrollchainingenabled ="true" scrollviewer.horizontalscrollbarvisibility="auto" scrollviewer.verticalscrollbarvisibility="auto" scrollviewer.horizontalscrollmode="enabled" scrollviewer.verticalscrollmode="enabled" itemssource="{binding source={staticresource collectionitems}}" grid.row="2"> <gridview.itemspanel> <itemspaneltemplate> <wrapgrid orientation="horizontal" /> </itemspaneltemplate> </gridview.itemspanel> <gridview.itemtemplate> <datatemplate> <grid margin="6" height="175" width="150" background="#fffafafa"> <grid.rowdefinitions> <rowdefinition height="85"/> <rowdefinition height="50"/> <rowdefinition height="30"/> </grid.rowdefinitions> <stackpanel background="#ff0a56bf" width="150" height="85" grid.row="0"> <image source="{binding path=thumnailurl}" stretch="uniformtofill" horizontalalignment="left" verticalalignment="top"/> </stackpanel> <textblock text="{binding path=videoname}" textwrapping="wrap" foreground="#ff017dd5" grid.row="1" horizontalalignment="left" verticalalignment="top" height="auto" fontsize="12"/> <button x:name="downloadbutton" grid.row="3" content="download video" horizontalalignment="left" verticalalignment="bottom" style="{staticresource downloadbuttonstyle}" click="downloadbutton_click" isenabled="{binding}" /> </grid> </datatemplate> </gridview.itemtemplate> </gridview>
unable bind button property isenabled. suggestion how ??
i have solve declaring property in class collectionitems bind , bind property button isenabled property , on selectionchangeevent selected item of grid view , set button isenabled property value true. working.
xaml file searchpanel.xaml
<gridview name="searchpanelgrid" selectionmode="single" horizontalalignment="left" scrollviewer.ishorizontalscrollchainingenabled="true" scrollviewer.isverticalscrollchainingenabled ="true" scrollviewer.horizontalscrollbarvisibility="auto" scrollviewer.verticalscrollbarvisibility="auto" scrollviewer.horizontalscrollmode="enabled" scrollviewer.verticalscrollmode="enabled" itemssource="{binding source={staticresource collectionitems}}" grid.row="2" selectionchanged="searchpanelgrid_selectionchanged"> <gridview.itemspanel> <itemspaneltemplate> <wrapgrid orientation="horizontal" /> </itemspaneltemplate> </gridview.itemspanel> <gridview.itemtemplate> <datatemplate> <grid margin="6" height="175" width="150" background="#fffafafa"> <grid.rowdefinitions> <rowdefinition height="85"/> <rowdefinition height="50"/> <rowdefinition height="30"/> </grid.rowdefinitions> <stackpanel background="#ff0a56bf" width="150" height="85" grid.row="0"> <image source="{binding path=thumnailurl}" stretch="uniformtofill" horizontalalignment="left" verticalalignment="top"/> </stackpanel> <textblock text="{binding path=videoname}" textwrapping="wrap" foreground="#ff017dd5" grid.row="1" horizontalalignment="left" verticalalignment="top" height="auto" fontsize="12"/> <button x:name="downloadbutton" grid.row="3" content="download video" horizontalalignment="left" verticalalignment="bottom" style="{staticresource downloadbuttonstyle}" click="downloadbutton_click" isenabled="{binding isselected}" /> </grid> </datatemplate> </gridview.itemtemplate> </gridview>
class bind itemssource propertry of gridview
public class videoinfo : inotifypropertychanged { private bool isselected; public bool isselected { { return isselected; } set { isselected = value; notifypropertychanged("isselected"); } } private string thumnailurl; public string thumnailurl { { return thumnailurl; } set { thumnailurl = value; notifypropertychanged("thumnailurl"); } } private string videoname; public string videoname { { return videoname; } set { videoname = value; notifypropertychanged("videoname"); } } public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string info) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(info)); } } }
.cs file searchpanel.xaml.cs on selectionchangeevent of gridview
private void searchpanelgrid_selectionchanged(object sender, selectionchangedeventargs e) { movieinfo info = (e.addeditems[0]) movieinfo; info.isselected = true; }
Comments
Post a Comment