Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   WPF calling function in mainWindow from another xaml window (http://www.xtremevbtalk.com/-net-general/328507-wpf-calling-function-mainwindow-xaml-window.html)

StealthRT 12-04-2016 11:19 AM

WPF calling function in mainWindow from another xaml window
 
Hey all I have been trying to figure out how to go about calling a public function on my mainWindow xaml from another xaml window.

MainWindow:
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

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>

page_Keyboard:
Code:

Call MainWindow.TopFlyoutCloseButtonOnClick(Nothing, Nothing)
The above has an error of:
Quote:

Error BC30469 Reference to a non-shared member requires an object reference.
page_Keyboard XAML:
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>

So how to do call TopFlyoutCloseButtonOnClick of the MainWindow from the page_Keyboard page?

PlausiblyDamp 12-05-2016 04:43 PM

The function TopFlyoutCloseButtonOnClick is an instance member of MainWindow, that means you need to refer to an instance of MainWindow - not the class itself.

You would either need to store the instance of MainWindow as a global variable or pass the current instance to the page_Keyboard instance you create.


All times are GMT -6. The time now is 11:26 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.