slightlyoff
asked on
Call a method in a parent from a child user control - VB.NET/WPF
Is it possible to call a method from a loaded user control?
MainWindow.xaml.vb loads user control Login.Xaml.vb. Login.Xaml.vb has a button on it. When that button is clicked, I want the method MainWindow.LoadUC(UserCont rol) to run.
This is my MainWindow.Xaml code:
And the Login User Control code is:
Maybe there's a better way to go about it. Basically, I need to load various user controls, and put them in the MainWindow's area, replacing the User Control that was there before.
Thanks for your help!!!
MainWindow.xaml.vb loads user control Login.Xaml.vb. Login.Xaml.vb has a button on it. When that button is clicked, I want the method MainWindow.LoadUC(UserCont
This is my MainWindow.Xaml code:
Imports System.IO
Imports Microsoft.PointOfService
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Net.NetworkInformation
Class MainWindow
Public Sub MainWindow()
InitializeComponent()
End Sub
Public Sub Window_Loaded()
LoadLogin()
End Sub
Public Sub Load_Login()
End Sub
Public Sub btnAdmin_Click()
End Sub
Public Sub btnLogOut_Click()
End Sub
Public Sub LoadUC(ByVal userControl As UserControl)
mainPanel.Children.Clear()
mainPanel.Children.Add(userControl)
End Sub
Private Sub LoadLogin()
Dim LoginScreen As New Login
'Content = LoginScreen
mainPanel.Children.Add(LoginScreen)
End Sub
End Class
And the Login User Control code is:
Public Class Login
Public uc As UserControl
Public Sub numberclick()
MsgBox("Number Click")
End Sub
Public Sub Login()
End Sub
Public Sub enterclick() Handles btnZero_Copy9.Click
MsgBox("Number Click")
End Sub
Public Sub clearclick()
MsgBox("Number Click")
uc = New UC_Text
'Not sure how to send "uc" back to MainWindow.
'This is what I want to do, but doesn't work:
MainWindow.LoadUC(uc)
End Sub
End Class
Maybe there's a better way to go about it. Basically, I need to load various user controls, and put them in the MainWindow's area, replacing the User Control that was there before.
Thanks for your help!!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok - I'll give it a try. I'm assuming, other thank vb.net markup, the winform and wpf function close to the same here?
I won't get to try it until later tonight, but I'll let you know.
Thanks for the help!
I won't get to try it until later tonight, but I'll let you know.
Thanks for the help!
Appropriate answers for the questions- weighted due to the time taken to write example code.
ASKER
In MainWindow code:
Open in new window
And then in Login
Open in new window
I'm new to WPF - I've been doing WinForms too long... sorry if it's a silly question.
Thanks again for the quick reply!
Steve