I am developing a WPF application and have developed a sliding navigation panel. I currently have it set up to two different buttons; one to open the navbar and one to close. However I am trying to implement a toggle so that when a single button is clicked the navbar opens and then when it is clicked again the navbar closes.
I have this all developed asides from the toggle functionality, in that I have a button, the functionality to trigger the opening and closing but not the toggling. So far I have the following code. As commented the first part opens the navbar and the second closes it.
WPF XAML
<Button x:Name="ToggleNavBtn" Click="ToggleNavBtn_Click" ToolTip="Toggle navigation" Height="50" Width="20" Content="|||" Background="#C20114" Foreground="#fff" ></Button>
C# Code
//Either 1 (Open) or 0 (Closed)
int state = 0;
if (state == 0)
{
//Open navigation
Storyboard sbOpen = Resources["OpenNavMenu"] as Storyboard;
sbOpen.Begin(NavMenu);
state = 1;
}
else if (state == 1)
{
// Closes navigation
Storyboard sb = Resources["CloseNavMenu"] as Storyboard;
sb.Begin(NavMenu);
state = 0;
}
I had planned to use a variable and change this after each part of the code is executed but obviously the variable state is local in the if statement so while this represents the functionality I desire, results in the navbar only ever opening.
My question is how would I ensure, as the navbar starts off closed, that when the button is pressed the navbar opens and then one its is pressed again is closes, repeating continuously no matter the amount I press the button.
Hopefully this make sense, thanks in advance.
Aucun commentaire:
Enregistrer un commentaire