Asked by:
How can I use ButtonBack of a Flyout?

Question
-
Hi,
I have a flyout
<SettingsFlyout
x:Class="Words_Gen.Views.AboutSettingsFlyout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Words_Gen.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
HeaderForeground="White"
HeaderBackground="#00b2f0"
Background="Navy"
BackClick="MySettingsBackClicked"
Title="About"
d:DesignWidth="346">private void MySettingsBackClicked(object sender, Windows.UI.Xaml.Controls.BackClickEventHandler e}
{
App.isBackAbout = true;
// First close our Flyout.
Popup parent = this.Parent as Popup;
if (parent != null)
parent.IsOpen = false;
}
}
What I want is to use BackClick.
I had this error:
Error 1 No overload for 'MySettingsBackClicked' matches delegate 'Windows.UI.Xaml.Controls.BackClickEventHandler'
ADRIAN DIBU
Wednesday, July 23, 2014 8:27 PM
All replies
-
What exactly you want to do ?
I believe the back button of the flyout works by default. It has a built-in feature to go back to the previous state.
Wednesday, July 23, 2014 9:51 PM -
The arguments passed to your BackClickEventHandler is a BackClickEventArgs, not a BackClickEventHandler
private void MySettingsBackClicked(object sender, Windows.UI.Xaml.Controls.BackClickEventHandler e}
should be
private void MySettingsBackClicked(object sender, Windows.UI.Xaml.Controls.BackClickEventArgs e}
Wednesday, July 23, 2014 9:58 PMModerator -
Hi,
Thanks for te propmpt answer.
What I want to do is when I start the flyout to
stop a dispatcherTimer(it works) and when I come back to restart
and continue to count the seconds in the MainPage.// In MainPage
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
dispatcherTimer.Stop();if (roamingSettings.Values.ContainsKey("MyValueTimeStop"))
{
roamingSettings.Values["MyValueTimeStop"] = StringToTime(TimerLog.Text);
}
else
{
roamingSettings.Values["MyValueTimeStop"] = "0";
}if (roamingSettings.Values.ContainsKey("MyValueScore"))
{
roamingSettings.Values["MyValueScore"] = txtScore.Text.ToString(); //hitsI.ToString(); // //
}
else
{
roamingSettings.Values["MyValueScore"] = "0";
}Words_Gen.Views.AboutSettingsFlyout aboutSF = new Words_Gen.Views.AboutSettingsFlyout();
aboutSF.ShowIndependent();
bottomAppBar.IsOpen = false;
}
//In flyout
private void MySettingsBackClicked(object sender, Windows.UI.Xaml.Controls.BackClickEventArgs e)
{
App.isBackAbout = true;
// First close our Flyout.
Popup parent = this.Parent as Popup;
if (parent != null){ parent.IsOpen = false;
}
}I tried in 3 places:
// In MainPage
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
System.Diagnostics.Debug.WriteLine("In OnNavigatedTo");
// if (App.isBackAbout == true)
// {
// dispatcherTimer.Start();
// }
}protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
System.Diagnostics.Debug.WriteLine("In OnNavigatedFrom");// if (App.isBackAbout == true)
// {
// dispatcherTimer.Start();
// }
}
private void Page_Load(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("In Page_Load");
if (App.isBackAbout == true)
{
dispatcherTimer.Start();
}
}I suppose to have a messsage where I am located when I am back.
The flyout works I can come back but not stop.
ThanksADRIAN DIBU
Thursday, July 24, 2014 8:11 PM -
Hi,
If I go from AppBar to a page I have the navigational parts of
the MainPage and works perfect, but not when I open a flyout, so my question is
question is how can I control dispatcherTimer when I go back from
flyout it belong to MainPage not to flyout?
ThanksADRIAN DIBU
Thursday, July 24, 2014 9:51 PM -
I think you are trying to stop the timer when the about flyout is open. But here you are starting. // check if block.
Also tell me does it shows the message?
protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); System.Diagnostics.Debug.WriteLine("In OnNavigatedTo"); // if (App.isBackAbout == true) // { // dispatcherTimer.Start(); // } }
Friday, July 25, 2014 12:52 AM -
Hi,
Thanks for the prompt answer.
Works pefect I stop the dispatcherTimer when I navigate from
AppBar of MainPage to a Help page and start when I came back,
olso
when I open the flyout I can stop the dispathcerTimer but I
can't start it when I close.private void AboutButton_Click(object sender, RoutedEventArgs e)
{
dispatcherTimer.Stop();if (roamingSettings.Values.ContainsKey("MyValueTimeStop"))
{
roamingSettings.Values["MyValueTimeStop"] = StringToTime(TimerLog.Text);
}
else
{
roamingSettings.Values["MyValueTimeStop"] = "0";
}if (roamingSettings.Values.ContainsKey("MyValueScore"))
{
roamingSettings.Values["MyValueScore"] = txtScore.Text.ToString(); //hitsI.ToString(); // //
}
else
{
roamingSettings.Values["MyValueScore"] = "0";
}Words_Gen.Views.AboutSettingsFlyout aboutSF = new Words_Gen.Views.AboutSettingsFlyout();
aboutSF.ShowIndependent();// bottomAppBar.IsOpen = false;
bottomAppBar.IsOpen = true;
}ADRIAN DIBU
Friday, July 25, 2014 1:27 PM -
Stop the timer in OnNavigatedTo method and Start it again in OnNavigatedFrom method. Also please send me the screenshot of the flyout, button and the timer. So i can tell you the solution more exactly.
- Proposed as answer by Abdul Rehman Aftab Friday, July 25, 2014 9:57 PM
- Unproposed as answer by Abdul Rehman Aftab Saturday, July 26, 2014 7:22 PM
Friday, July 25, 2014 9:54 PM -
Hi,
Thanks for the answer.When a flyout apear or is closed it is no navigation so
OnNavigatedTo and OnNavigatedFrom not working.It works when from AppBar open a page like this
In MainPage
private void HelpButton_Click(object sender, RoutedEventArgs e)
{
if (this.Frame != null)
{
this.Frame.Navigate(typeof(HelpMainPage));dispatcherTimer.Stop();
if (roamingSettings.Values.ContainsKey("MyValueTimeStop"))
{
roamingSettings.Values["MyValueTimeStop"] = StringToTime(TimerLog.Text);
}
else
{
roamingSettings.Values["MyValueTimeStop"] = "0";
}if (roamingSettings.Values.ContainsKey("MyValueScore"))
{
roamingSettings.Values["MyValueScore"] = txtScore.Text.ToString(); //hitsI.ToString();
}
else
{
roamingSettings.Values["MyValueScore"] = "0";
}
}
bottomAppBar.IsOpen = true;
}And
public MainPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;dispatcherTimer.Start();
}If is a flyout open from AppBar works too see code:
In MainPage
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
dispatcherTimer.Stop();if (roamingSettings.Values.ContainsKey("MyValueTimeStop"))
{
// roamingSettings.Values["MyValueTimeStop"] = (timesTicked - timeStop).ToString();
roamingSettings.Values["MyValueTimeStop"] = StringToTime(TimerLog.Text);
}
else
{
roamingSettings.Values["MyValueTimeStop"] = "0";
}if (roamingSettings.Values.ContainsKey("MyValueScore"))
{
roamingSettings.Values["MyValueScore"] = txtScore.Text.ToString(); //hitsI.ToString(); // //
}
else
{
roamingSettings.Values["MyValueScore"] = "0";
}Words_Gen.Views.AboutSettingsFlyout aboutSF = new Words_Gen.Views.AboutSettingsFlyout();
// When the settings flyout is opened from the app bar instead of from
// the setting charm, use the ShowIndependent() method.
aboutSF.ShowIndependent();bottomAppBar.IsOpen = true;
}
In flyout:
private void MySettingsBackClicked(object sender, Windows.UI.Xaml.Controls.BackClickEventArgs e)
{
System.Diagnostics.Debug.WriteLine("In MySettingsBackClicked");
App.myValueAbout = "1";// First close our Flyout.
Popup parent = this.Parent as Popup;
if (parent != null)
{
parent.IsOpen = false;
}
notifyApp();
}private void notifyApp()
{
App.passedVal = App.myValueTimeStop + "(" + App.myValueScore + ")" +
App.myValueBackground + "[" + App.myValueSelectedIndexCategory + "]" +
App.myValueAbout + "," +
App.myValueHelp + ";"
;
System.Diagnostics.Debug.WriteLine("App.passedVal.ToString(): " + App.passedVal.ToString());
rootPage.NotifyUser(App.passedVal, NotifyType.StatusMessage);
}
and in MainPagepublic void NotifyUser(string strMessage, NotifyType type)
{
System.Diagnostics.Debug.WriteLine("strMessage:" + strMessage);
switch (type)
{
// Use the status message style.
case NotifyType.StatusMessage:
StatusBlock.Style = Resources["StatusStyle"] as Style;
break;
// Use the error message style.
case NotifyType.ErrorMessage:
StatusBlock.Style = Resources["ErrorStyle"] as Style;
break;
}
StatusBlock.Text = strMessage;App.passedVal = strMessage;
int intA = App.passedVal.Trim().IndexOf('(');
int intB = App.passedVal.Trim().IndexOf(')');App.pTimeStop = App.passedVal.ToString().Trim().Substring(0, intA);
App.pScore = App.passedVal.ToString().Trim().Substring(intA + 1, intB - intA - 1);int intC = App.passedVal.Trim().IndexOf('[');
int intD = App.passedVal.Trim().IndexOf(']');App.pBackground = App.passedVal.ToString().Trim().Substring(intB + 1, intC - intB - 1);
App.pIndexCategory = App.passedVal.ToString().Trim().Substring(intC + 1, intD - intC - 1);int intE = App.passedVal.Trim().IndexOf(',');
App.pAbout = App.passedVal.ToString().Trim().Substring(intD + 1, intE - intD - 1);changeBackground();
changeScore();
changeAbout();
}
private void changeAbout()
{
if (App.myValueAbout.ToString().Trim().Equals("0"))
{
dispatcherTimer.Stop();
}
if (App.myValueAbout.ToString().Trim().Equals("1"))
{
dispatcherTimer.Start();
}
}Now start my problem. When I the flyout from charm with the code from App.xmal.cs
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
System.Diagnostics.Debug.WriteLine("In App Init ");
Application.Current.Resuming += new EventHandler<Object>(App_Resuming); // Added//Do your data loading stuff here
if (roamingSettings.Values.ContainsKey("MyValueTimeStop"))
{
App.myValueTimeStop = roamingSettings.Values["MyValueTimeStop"].ToString();
}
else
{
roamingSettings.Values["MyValueTimeStop"] = "0";
App.myValueTimeStop = "0";
}if (roamingSettings.Values.ContainsKey("MyValueScore"))
{
App.myValueScore = roamingSettings.Values["MyValueScore"].ToString();
}
else
{
roamingSettings.Values["MyValueScore"] = "0";
App.myValueScore = "0";
}if (roamingSettings.Values.ContainsKey("MyValueBackground"))
{
App.myValueBackground = roamingSettings.Values["MyValueBackground"].ToString();
}
else
{
roamingSettings.Values["MyValueBackground"] = "0";
App.myValueBackground = "0";
}
if (roamingSettings.Values.ContainsKey("MyValueSelectedIndexCategory"))
{
App.myValueSelectedIndexCategory = roamingSettings.Values["MyValueSelectedIndexCategory"].ToString();
}
else
{
roamingSettings.Values["MyValueSelectedIndexCategory"] = "0";
App.myValueSelectedIndexCategory = "0";
}
if (roamingSettings.Values.ContainsKey("MyValueAbout"))
{
App.myValueAbout = roamingSettings.Values["MyValueAbout"].ToString();
}
else
{
roamingSettings.Values["MyValueAbout"] = "0";
App.myValueAbout = "0";
}App.passedVal = App.myValueTimeStop + "(" + App.myValueScore + ")" +
App.myValueBackground + "[" + App.myValueSelectedIndexCategory + "]" +
App.myValueAbout + "," +
;int intA = App.passedVal.Trim().IndexOf('(');
int intB = App.passedVal.Trim().IndexOf(')');App.pTimeStop = App.passedVal.ToString().Trim().Substring(0, intA);
App.pScore = App.passedVal.ToString().Trim().Substring(intA + 1, intB - intA - 1);int intC = App.passedVal.Trim().IndexOf('[');
int intD = App.passedVal.Trim().IndexOf(']');App.pBackground = App.passedVal.ToString().Trim().Substring(intB + 1, intC - intB - 1);
App.pIndexCategory = App.passedVal.ToString().Trim().Substring(intC + 1, intD - intC - 1);int intE = App.passedVal.Trim().IndexOf(',');
App.pAbout = App.passedVal.ToString().Trim().Substring(intD + 1, intE - intD - 1);if (pTimeStop.Equals("0"))
{
App.isTimeStopForced = false;
}
else
{
App.isTimeStopForced = true;
}
}
private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
args.Request.ApplicationCommands.Add(new SettingsCommand(
"Preferences", "Preferences", (handler) => ShowPrefSettingsFlyout()));args.Request.ApplicationCommands.Add(new SettingsCommand(
"Help", "Help", (handler) => ShowHelpSettingsFlyout()));args.Request.ApplicationCommands.Add(new SettingsCommand(
"About", "About", (handler) => ShowAboutSettingsFlyout()));
}public void ShowAboutSettingsFlyout()
{
AboutSettingsFlyout aboutSF = new AboutSettingsFlyout();aboutSF.BackClick += AboutSettingsFlyout_BackClick;
aboutSF.Show();
}
void AboutSettingsFlyout_BackClick(object sender, BackClickEventArgs e)
{
App.myValueAbout = "1";App.passedVal = App.myValueTimeStop + "(" + App.myValueScore + ")" +
App.myValueBackground + "[" + App.myValueSelectedIndexCategory + "]" +
App.myValueAbout + "," +
;}
ADRIAN DIBU
Saturday, July 26, 2014 2:22 PM -
Hi,
I found the solution.
First I moved the charm from App to MainPage
public MainPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;bottomAppBar.IsOpen = true;
// // This is a static public property that will allow downstream pages to get
// a handle to the MainPage instance in order to call methods that are in this class.
Current = this;
DispatcherTimerSetup();dispatcherTimer.Start();
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;}
void OnPopupClosed(object sender, object e)
{
Window.Current.Activated -= OnWindowActivated;
dispatcherTimer.Start();
}
private void OnWindowActivated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
{
_settingsPopup.IsOpen = false;
}
}private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
args.Request.ApplicationCommands.Add(new SettingsCommand(
"About", "About", (handler) => ShowAboutSettingsFlyout()));
}public void ShowAboutSettingsFlyout()
{
AboutSettingsFlyout aboutSF = new AboutSettingsFlyout();aboutSF.BackClick += AboutSettingsFlyout_BackClick;
aboutSF.Show();
// aboutSF.ShowIndependent();App.myValueAbout = "0";
App.passedVal = App.myValueTimeStop + "(" + App.myValueScore + ")" +
App.myValueBackground + "[" + App.myValueSelectedIndexCategory + "]" +
App.myValueAbout + "," +
App.myValueHelp + ";"
;
changeAbout();
}
void AboutSettingsFlyout_BackClick(object sender, BackClickEventArgs e)
{App.myValueAbout = "1";
App.passedVal = App.myValueTimeStop + "(" + App.myValueScore + ")" +
App.myValueBackground + "[" + App.myValueSelectedIndexCategory + "]" +
App.myValueAbout + "," +
App.myValueHelp + ";"
;
changeAbout();
}Now I can start/stop when I lunch a page from AppBar, when I lunch
flyout from AppBar or Charm.Let me know if you find a simple way to do it.
Thanks for your help.
ADRIAN DIBU
- Proposed as answer by Molly Bryant Monday, July 28, 2014 2:29 AM
Saturday, July 26, 2014 4:06 PM -
Hey i found a very simple and verified solution for you. Try to raise the Unloaded Event of the Settings Flyout. I just printed a message on unload event, and it works fine. Try this. Hope it will work. :)
- Proposed as answer by Abdul Rehman Aftab Saturday, July 26, 2014 7:23 PM
Saturday, July 26, 2014 7:23 PM -
Hi,
Thanks for the answer, but I don't know where you print the message on
unload event.
Thanks
Best regards
ADRIAN DIBU
Saturday, July 26, 2014 10:15 PM