page in frame how to talk to controls in window?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: page in frame how to talk to controls in window?

  1. #1
    Join Date
    Nov 2009
    Posts
    3

    page in frame how to talk to controls in window?

    Sometimes I can't think of the correct google searches, so please forgive me for asking such a basic question.

    I have a MainWindow from the Window class. It contains a Frame control. The frame control displays a Page from the Page class. The page has a button.

    How do I make stuff happen on the Window when someone clicks the button on the page in the frame that is on the window?

    Thanks in advance.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,486

    Re: page in frame how to talk to controls in window?

    Add an on click button handler.

  3. #3
    Join Date
    Nov 2009
    Posts
    3

    Re: page in frame how to talk to controls in window?

    I think you misunderstand me. I am asking how to manipulate a control that is not in the scope of the button.

    void onClick(object sender, EventArgs args) {
    control.DoSomething();
    }

    I can't call "control's" doSomething() method because control isn't a member of this.

    How would I talk to a control on a window, from a button, on a page, in a Frame on the window?

    THanks in advance.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,486

    Re: page in frame how to talk to controls in window?

    I'll explain one way to do this, but then recommend that you take a different approach.

    All you need to do is pass a reference of the window when you create the page and expose the control as a public property of the window. One way to do this is to pass the window reference in the Page constructor and then store it as a field.

    That being said, it's usually not good to have such tight coupling between controls from one window (or page) and other window (or page). Coding this way, can lead to difficult to maintain code.

    Instead, create a model for the data, and bind the views to the model (or bind to a ViewModel of the data). That way, when you make a change or perform an action in one window (or page), the data changes and any other view that is bound to the data will get the change (or be able to act on the change event). The benefit to this approach is that the views are loosely coupled and one view doesn't need to know about the controls from another view.

  5. #5
    Join Date
    Nov 2009
    Posts
    3

    Re: page in frame how to talk to controls in window?

    Alright, thanks. I searched "ViewModel" and "Data Model" and I think I came up with something related to WPF...

    http://blogs.msdn.com/dancre/archive...23/676300.aspx

    I think this is what you are talking about.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center