dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: New to WPF VB, how to access control between window1 and window2 not using mainwindow

  1. #1
    Join Date
    Jan 2019
    Posts
    3

    Angry New to WPF VB, how to access control between window1 and window2 not using mainwindow

    Hey guys,

    I am extremely new to WPF VB programming. I have a form window1 which is a loading bar used to open and copy excel files to a datagrid on window2. However I am unable to just use window2.datagrid1 or the name when created frmload2.datagrid1.

    Any help?

    MainWindow:
    dim frmload as new window1
    dim frmload2 as new window2
    frmload.show()
    frmload2.show()


    window1:
    excel stuff
    frmload2.datagrid. <---Not working

    Window2:
    BLANK

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

    Re: New to WPF VB, how to access control between window1 and window2 not using mainwi

    Generally accessing a control from another control has always been an expedient way of doind things but not necessarily a good way of doing things (because it breaks encapsulation). Of course a lot of folks did it that way and suffered through working out issues with trying to access data that was in the form of a parent of a parent of a parent.

    A better way to code is to separate the data (in a model) from the UI form(s) and have the form bind to the data. Using this approach, one form doesn't get at data by trying to access a control in another form, it simply binds to that data in the model.

    In WPF, form data is bound to an observable model and the model is passed around (i.e as new forms are opened, it binds and update data in the model).

    To learn this approach, search the internet for "WPF observable binding examples". There is a good example called "family show" that is probably available in VB.Net.

  3. #3
    Join Date
    Jan 2019
    Posts
    3

    Re: New to WPF VB, how to access control between window1 and window2 not using mainwi

    Thanks for your response! Your method of communication was very helpful in understanding the process. I was able to find this as an example of the databinding. This is pretty easy to understand.

    https://www.codeproject.com/Tips/650...WPF-for-VB-NET

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

    Re: New to WPF VB, how to access control between window1 and window2 not using mainwi

    Great. Looks like the perfect example.

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




On-Demand Webinars (sponsored)