Results 1 to 8 of 8

Thread: Passing an object by refrence to multipule UI controls

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Passing an object by refrence to multipule UI controls

    Hi Guys,

    I just wanted to know if this is the correct way of doing this. I have a utility that takes the for of a wizard. There are five pages to this wizard and each page tends to need data that is selected from the other.

    The way I was intending on doing this was to create an object that would hold all of the needed data and pass it by reference to each page as this means that I only need one object to track all of the data. Is this the correct way of doing this or am I going about it the wrong way?

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Passing an object by refrence to multipule UI controls

    Just to be sure, by a page you mean a web page and not window form?
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Passing an object by refrence to multipule UI controls

    Actually they are WPF pages but function somewhat like ASP.NET pages in so far as you navigate to a page as opposed to opening a window!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing an object by refrence to multipule UI controls

    I'd be inclined to use a singleton, which negates the need to pass the object from page to page.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Passing an object by refrence to multipule UI controls

    I've always been told the singleton pattern is not good design wise but in this case I suppose it makes sense. I seem to run into this issue quite a bit lately, it is hard not to be brittle with regards to UI coupling as I find there is only so much that can be abstracted out of the UI class itself.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing an object by refrence to multipule UI controls

    Using a singleton won't really be any more brittle than passing an instance of a class from page to page, assuming that you're passing it as it's actual type. If you're using an interface rather than a concrete type then that does become more robust. If you really want to follow good design principles in WPF then you should probably research the MVVM pattern, which is pretty much the new MVC/MVP for WPF.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Passing an object by refrence to multipule UI controls

    That's a lot of acronyms!

    I agree a singleton makes sense, there is not a lot of data, the application is small and there is no expansion, it does what it does and singularly. As for the other patterns I have never heard of them so I will have to look them up.

    This thread makes me wonder though is the issue more about bad layout. I had assumed that the best way for a wizard style application or one that follows a singular logical layout should have a global object to store the needed data as it pulls it from the pages. In my head this made sense as it was the only way I could see that the data could be retrieved.

    I thought it was a simple issue of passing values back to the caller but because each page opens the next the caller is the previous page and not the application. Hmmm, UI's certainly make programming harder!

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Passing an object by refrence to multipule UI controls

    Ok, had a look over the MVVM and honestly I only understand it in high level so I think im going to take a few days to pour over this and research it a bit more!

Posting Permissions

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



Click Here to Expand Forum to Full Width