Solved

VB.NET WPF and Controling controls on different windows

Posted on 2014-11-28
2
502 Views
Last Modified: 2014-12-06
I'm new to WPF and I'm struggling with some basic databinding and window sharing concepts.  In windows forms, controlling objects on other windows was easy.  In WPF, I can't seem to get it to work.

For example, I have three windwos at the moment:

1. MainWindow
2. LoginStart
3. ControlPanel

MainWindow is mostly what I'm using for the background and to display messages.  I have a label in the upper right hand corner for messages, called "lblInfo".  I also have a button in the lower right that is labeled "Login" - clicking this opens LoginStart.

LoginStart is a 12 button form, with a textbox for logging in.  The buttons are numbered like a keypad, with CLR and GO at the bottom.  CLR erases what's in the textbox, and GO submits the information for processing.

LoginStart is a transparent window, so the buttons just appear as if they are part of MainWindow.  When someone logs in, I want the name of the person to appear in lblInfo on MainWindow.

I thought I'd accomplish this in loginStart.xaml.vb using:
mw = new MainWindow
mw.lblInfo.Content  = FirstName & " " & LastName & " is now logged in."

Open in new window


I don't have any errors when I run this, it just doesn't do anything.

I've read tutorials and watched youtube videos on databinding, and it seems like that's the answer, but it also seems like all the suggestions I've read are much more complex than they need to be.  They're also in C#, which I'm learning, but not totally comfortable with.

So in short, my question is, what do I need to do to access controls on other windows using WPF?

Thanks for your help!!!
0
Comment
Question by:slightlyoff
2 Comments
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 40472610
The short reason:
You have created an instance of MainWindow in code and set a property - but you can't see any result because, as yet, there has been no request to Show the window.
If MainWindow already on display, then that is another instance, created in some other manner, and your code doesn't refer to it.

There are many ways to address the requirement.

One is for the main window to open the login window as dialog when the login button is clicked. The main window can then retrieve data from Login, or pass a reference to itself to the login window before calling ShowDialog.

Another is to code the Login window as a UserControl rather than a Window and include that in the xaml for the main window,  binding the visibility of the control to an IsLoggedOn Boolean property (via a ValueConverter).

My advice is to search the net for articles on the MVVM approach to application structure and follow that - there may be a learning curve at the beginning, but it's worth it.
0
 
LVL 1

Author Comment

by:slightlyoff
ID: 40484826
Thanks Mike,

I think you're right.  I'm working on learning MVVM.  Thanks for the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Round a string to two digits 12 30
Javascript Refresh Parent Page from Popup 3 48
Disable and re-enable a dynamic System.Timers.Timer 6 39
Close tabpage of custom control 9 23
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now