c# - Tab Item remains selected WPF -
i using tab_selectionchanged event of tabcontrol in wpf. contains 3 tab items. have restrict user navigate other tabs i.e settings , schedule while work in-progress on home tab. while using event facing issue i.e. if clicked on settings tab shows me popup "you cannot navigate while work in progress" , when clicked on schedule tab after clicking on settings tab shows me same popup twice. reason behind settings tab remains selected.here code this:
private void tabmhpc_selectionchanged(object sender, selectionchangedeventargs e) { tabcontrol tab = (tabcontrol)sender; if (tab.selectedindex != -1) { if (tab.selectedindex != 4 && tab.selectedindex != 1 && tab.selectedindex != 0) { if (scanstatus == "fixing") { messagebox.show(applicationinfo.applicationname + " still busy in fixing issues.please let fixation complete.", applicationinfo.applicationname, messageboxbutton.ok, messageboximage.information); hometab.isselected = true; } else { messagebox.show(applicationinfo.applicationname + " still busy scanning issues.please stop before leave home tab.", applicationinfo.applicationname, messageboxbutton.ok, messageboximage.information); hometab.isselected = true; } } else if (tab.selectedindex == 0) { } } }
i want previous tab item isselected property gets false when move on other tabitem.
instead of handling selectionchanged
event, should data bind property of suitable type tabcontrol.selecteditem
property:
<tabcontrol selecteditem="{binding yourselecteditemproperty}" ... />
when this, able stop tabitem
being changed:
public yourdatatype yourselecteditemproperty { { return yourselecteditemproperty; } set { if (isoktochangetabitem) { yourselecteditemproperty = value; notifypropertychanged("yourselecteditemproperty"); } } }
the final part of solution set isoktochangetabitem
variable true
or false
depending on whether ok user change selected tabitem
or not.
Comments
Post a Comment