This question is locked. New answers and comments are not allowed.
I am working with multiple tabs in a silverlight app. I need to do what I think is a fairly simple operation. However it is causing me some problems. The scenario is as follows, when the user changes tabs, I need to check if there are any changes pending and prompt the user to either save them, discard them or cancel and stay in the tab. Furthermore, if they select save, and there are validation errors, I need to prompt the user of the problem and stay on the current tab.
Seems pretty simple. Catch either the PreviewSelectionChanged event or the SelectionChanged event. Do the check and set handled = true if I need to stay on the current tab. The problem is, the confirmation box that I am using doesn't block the UI thread. So I have to set handled=true to cancel out of the change, then change the tab programatically after the user makes their selection. I have tried this pretty much every way I can. Here is how I currently have the code:
I'm stepping through the code and it is working correctly. There are a couple issues:
1. Even though I am setting handled = true, the selectedIndex of the tab control stays with the new tab the user selected.To combat this, I try resetting the selectedIndex back to the previous value.
2. When I set the selectedIndex on the tabControl in the changeTab method above it doesn't work.
I know there has to be some other way of doing this. The main problem I have is that the confirmation box isn't blocking the UI thread (as it shouldn't) but this means that the tab switching has already occured when the user disposes of the confirmation box.
Seems pretty simple. Catch either the PreviewSelectionChanged event or the SelectionChanged event. Do the check and set handled = true if I need to stay on the current tab. The problem is, the confirmation box that I am using doesn't block the UI thread. So I have to set handled=true to cancel out of the change, then change the tab programatically after the user makes their selection. I have tried this pretty much every way I can. Here is how I currently have the code:
private
void
changeTab()
{
tabControl.SelectedIndex = selectedTab;
}
bool
checkForSave =
true
;
int
currentTab = 0;
int
selectedTab = 0;
private
void
tabControl_PreviewSelectionChanged(
object
sender, RadSelectionChangedEventArgs ar)
{
if
(currentDataGrid ==
null
)
{
currentTab = tabControl.SelectedIndex;
return
;
}
if
(checkForSave)
{
ar.Handled =
true
;
selectedTab = tabControl.SelectedIndex;
tabControl.SelectedIndex = currentTab;
//This method does the confirmation, sets checkForSave = false and calls the changeTab method.
CheckSave(changeTab);
}
else
{
currentTab = tabControl.SelectedIndex;
checkForSave =
false
;
}
}
I'm stepping through the code and it is working correctly. There are a couple issues:
1. Even though I am setting handled = true, the selectedIndex of the tab control stays with the new tab the user selected.To combat this, I try resetting the selectedIndex back to the previous value.
2. When I set the selectedIndex on the tabControl in the changeTab method above it doesn't work.
I know there has to be some other way of doing this. The main problem I have is that the confirmation box isn't blocking the UI thread (as it shouldn't) but this means that the tab switching has already occured when the user disposes of the confirmation box.