WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
Go Back  Xtreme Visual Basic Talk > > > WPF calling function in mainWindow from another xaml window


Reply
 
Thread Tools Display Modes
  #1  
Old 12-04-2016, 11:19 AM
StealthRT's Avatar
StealthRT StealthRT is offline
Contributor
 
Join Date: Aug 2002
Posts: 785
Question 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?
Reply With Quote
  #2  
Old 12-05-2016, 04:43 PM
PlausiblyDamp's Avatar
PlausiblyDampWPF calling function in mainWindow from another xaml window PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

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.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply

Tags
mainwindow, xaml, flyout, page_keyboard, error, class, object, flyout.isopen, call, public, reference, function, calling, window, page, routedeventargs, yourmahappflyout.isopen, false, non-shared, bc30469, requires, [more, code, figure, hey


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
 
WPF calling function in mainWindow from another xaml window
WPF calling function in mainWindow from another xaml window
 
-->