Hey all I am trying to get my flyout box to close on my WPF Page XAML I created:
Code:
<Page x:Class="page_Keyboard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:newRegisterProg"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Background="Transparent"
Height="335"
Width="1336"
x:Name="kbMenu"
Title="page_Keyboard">
<Grid x:Name="theKBGrid">
<Button x:Name="keyBoard_1" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="1036,10,220,255" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Width="80" Content="1" Tag="numpad"/>
[more code here.......]
<Button x:Name="keyBoard_period" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="1226,250,30,15" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Width="80" Content="." Tag="period"/>
<!-- Start QWERTY Keys -->
<Button x:Name="keyBoard_Q" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="23,10,1233,255" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Width="80" Content="Q" Tag="keyboard"/>
<Button x:Name="keyBoard_W" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="116,10,1140,255" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Width="80" Content="W" Tag="keyboard"/>
<Button x:Name="keyBoard_blank1" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="23,249,1140,16" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Content="CLOSE" Tag="goback"/>
</Grid>
</Page>
The Page code for just the button clicks:
Code:
Private Sub loopThruButtons(sender As Object, e As RoutedEventArgs)
Dim theButton as Button = TryCast(sender, Button)
Dim mw As New MainWindow()
If theButton.caption = "CLOSE" Then
mw.TopFlyoutCloseButtonOnClick(Nothing, Nothing)
End If
End Sub
The Content="CLOSE" is the button I am using in order to close the said flyout. However, when it kicks off that function on the MainWindow it hits the yourMahAppFlyout.IsOpen = False but it never closes the flyout!
My MainWindow XAML:
Code:
<Controls:MetroWindow
x:Name="frmCRter"
x:Class="MainWindow"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:newRegisterProg"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
Background="{DynamicResource MaterialDesignPaper}"
Height="768" Width="1336" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterScreen" IsWindowDraggable="False" IsTabStop="False" IsMinButtonEnabled="False" IsMaxRestoreButtonEnabled="False" IsCloseButtonEnabled="False" ShowCloseButton="False" ShowDialogsOverTitleBar="False" ShowIconOnTitleBar="False" ShowMinButton="False" ShowMaxRestoreButton="False" ShowSystemMenuOnRightClick="False" ShowTitleBar="False" TitlebarHeight="0" WindowStyle="None" Title="frmCRter">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="134,95,0,0" VerticalAlignment="Top" Width="75" Style="{StaticResource AccentedSquareButtonStyle}"/>
</Grid>
<Controls:MetroWindow.Flyouts>
<Controls:FlyoutsControl x:Name="flyoutsControl">
<Controls:Flyout AnimateOpacity="True"
TitleVisibility="Collapsed"
CloseButtonVisibility="Collapsed"
IsModal="True"
MinHeight="335"
Position="Bottom"
Width="1336"
Height="335"
Theme="Adapt"
x:Name="yourMahAppFlyout">
<Grid>
<Frame x:Name="CenterFrame"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
HorizontalAlignment="Left"
HorizontalContentAlignment="Center"
Source="page_Keyboard.xaml"
Background="Transparent"
Width="1336" />
</Grid>
</Controls:Flyout>
</Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>
</Controls:MetroWindow>
And the MainWindow code:
Code:
Class MainWindow
Inherits MetroWindow
Private Sub ToggleFlyout(index As Integer)
Dim flyout = TryCast(Me.Flyouts.Items(index), Flyout)
If flyout Is Nothing Then
Return
End If
flyout.IsOpen = Not flyout.IsOpen
End Sub
Public Sub TopFlyoutCloseButtonOnClick(sender As Object, e As RoutedEventArgs)
yourMahAppFlyout.IsOpen = False
End Sub
End Class
If I just add a close button to the code area and have the flyout pop up without using the Frame - using that close button works just fine to close the flyout.
Code:
<Controls:MetroWindow.Flyouts>
<Controls:FlyoutsControl x:Name="flyoutsControl">
<Controls:Flyout AnimateOpacity="True"
TitleVisibility="Collapsed"
CloseButtonVisibility="Collapsed"
IsModal="True"
MinHeight="335"
Position="Bottom"
Width="1336"
Height="335"
Theme="Adapt"
x:Name="yourMahAppFlyout">
<Grid>
<Button x:Name="CloseButton" materialDesign:ShadowAssist.ShadowDepth="Depth1" FontSize="40" FontWeight="Bold" Style="{StaticResource MaterialDesignRaisedDarkButton}" Margin="23,249,1140,16" materialDesign:RippleAssist.Feedback="AliceBlue" Height="70" Click="TopFlyoutCloseButtonOnClick" Content="Close" />
</Grid>
</Controls:Flyout>
</Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>
What could I be missing in order for it to close the flyout?