Results 1 to 7 of 7

Thread: Does WPF have a place to store data?

  1. #1

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

    Does WPF have a place to store data?

    I have been learning about MVVM and it seems to make sense, mostly! One of the things I notice is that the idea is that a model is a place that gets data be it from a database or webservice or other applicable place.

    What i want to know is what if the data is so small you only what it in memory is there a way for one to save in memory outside the instantiation of a particular model? That way the models that need to use this data can access this store when instantiated and their destruction would not kill of the store!

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

    Re: Does WPF have a place to store data?

    As you already know, I dont have much knowledge about MVVM, but to me it seems like all you are really wanting to do is just keep some data in memory and have several classes be able to access that data. So cant you just have a separate class that holds this data in Shared objects? I dont know what sort of data you are talking about but if it was just a List(Of String) or something then you could just have something like:

    vb Code:
    1. Public Class DataStorage
    2.  
    3.       Public Shared DataList As New List(Of String)
    4.  
    5. End Class
    Then whenever you wanted to load data into (or remove data from) that list then you just refer to it like so:
    vb Code:
    1. DataStorage.DataList.Add("a new string")
    or am I missing something?
    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: Does WPF have a place to store data?

    No no that makes sense so if I have this right the class is instantiated but the information which is static (shared) is not therefore keeps its values?

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

    Re: Does WPF have a place to store data?

    Well no you dont need to instantiate the class, that is the point of Shared/Static - you can access Shared/Static objects without an instance of the class that they are in
    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: Does WPF have a place to store data?

    Oh I see, and what about just declaring a class in the app.xaml.cs? Afterall the data is related to the application and this would give other classes access right?

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

    Re: Does WPF have a place to store data?

    I'm not sure how the app.xaml.cs works, is it just like a place that any code in the application can access? I'm not 100% sure whether you can actually define a class within it - Personally I would just create a new class file for it
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

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


  7. #7

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

    Re: Does WPF have a place to store data?

    Tested it it doesn't work...

    Im going to have to read up on static objects cause how I think they work and how they actually work seem to be different!

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