Results 1 to 5 of 5

Thread: An MVVM Question

  1. #1

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

    An MVVM Question

    Hi guys, I am currently learning MVVM and have a few questions for anyone who has taken the time to look it up.

    The first is this thing of passing classes to other classes, any of the video examples I have seen do something like this:

    Code:
    public class viewModel
    {
         readonly dataModel _model;
         
         public viewModel  (dataModel model)
         {
              _model = dataModel;
         }
    }
    and then they proceed to databind to the viewmodel properties but if the class is read only how do they send data back to it? Is it just a case that they are not sending back data in that instance?

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: An MVVM Question

    I'm not sure if this helps and you might already know this but I'll explain anyway: Just because a property/variable is read only, does not mean you cannot modify it It simply means that you cannot replace the entire object that the property is holding. You can still access the properties of that object and modify them (if you didnt want that to be possible then you would have to make the properties read-only as well)

    For example:
    vb Code:
    1. Private ReadOnly MyTcpClient As New Net.Sockets.TcpClient
    2.  
    3. Private Sub SomeMethod()
    4.         'This works, as we are modifying a property of the TcpClient that the variable refers to
    5.         MyTcpClient.NoDelay = False
    6.  
    7.         'This does not, as we are trying to replace the entire object reference
    8.         MyTcpClient = New Net.Sockets.TcpClient
    9. End Sub
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

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

    Re: An MVVM Question

    Ok that makes sense but if your are not instantiating does that mean you are accessing the same one?

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: An MVVM Question

    Huh?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

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

    Re: An MVVM Question

    Oh I dunno, Im lost, walking and running come to mind, im going back to basics and taking out my C#2008 and the 3.5 platform book. Its annoying that its stuff like this that gets me yet I have no problem cracking open XPS files and reading them ggrrrr!

    Thanks for the help chris!

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