I want to display some nested data structure in my silver light application.
I am using SQL server and Entityframework.
Say I have a class ClassA which has property of collection of ClassB.
ClassB also can contain a collection of ClassB itself (say till 5th Level).
ClassB also contains a collection of another class ClassA.
Can anyone help me the best way to display this in silver light page?
Related
Making my first WPF MVVM application and I have a question about the organization of View Models. I have a ClassA with a one to many relationship with ClassB
I want the main view to look like this. It contains some info from class A along with a listview of all Class B instances that are associated with Class A
I have come up with two approaches but I am unsure about which organization, if either, is considered the best approach. (This is a standard CRUD application: I want to be able to modify Class A, Add and remove Class B from Class A, modify Class B)
Approach 1
The main view model contains a ClassAViewModel and a List of ClassBViewModels
Approach 2
The main view model contains a ClassAViewModel. The ClassAViewModel handels its own list of ClassBViewModels
I would greatly appreciate any input on which approach will be best for me / a new approach. I'm also open to any recommendations of resources that would help me better understand software design and best practices in general
The main view model contains a ClassAViewModel and a List of ClassBViewModels
No. The ClassB view models are only needed for views of ClassB, which is not what your main view is. Your main view will have a list (ListBox or ItemsControl) of the array of ClassB in your view model and templated to a user control that knows how to display them.
That user control then has its context as ClassBViewModel (only one) and handles the rest of the responsabilities for ClassB specifically.
The main view model contains a ClassAViewModel. The ClassAViewModel handels its own list of ClassBViewModels
Again, no. At best you're confusing view models (the data necessary to display in the view your model types) and models (which correspond to the data itself). AVM links to an A, which links to a list of B, which, when bound to a view themselves, go through a BVM (if necessary).
New to WPF. I have a Product model that is an L2S entity. I am creating an application in WPF to edit the product information to potentially replace an old Windows forms app I have. the application has a tab control with a number of tabs on it, such as Packaging, Marketing, Photos, Construction, etc.
My question is how do I structure this in a MVVM system. Do I have a separate view for each tab, each with it's own view model relating to it's particular subset of the Product model? Or do I have a single view with the tab control and all of the fields and a single view model to encompass the model in it's entirety? Or am I going about it completely wrong?
I feel like the first option is the way to go, but then I am also unsure of how to share the same model across multiple view models. Can anyone shed some light on this for me?
--Edit--
Examples of data on the pages:
Marketing has several text fields, and a few subset entity collections such as features, applications, and cross references.
Photos handles a collection of Photos for the product
Packaging and Construction are each a large collection of text fields/combos/checkboxes related to their respective information in the Product
With this minimum of info you've provided I would suggest following solution:
Main ProductView view
Separate View for the each tab
Main container ViewModel: ProductViewModel
For complex tabs separate view model as well. For instance you would have a separate PackagingViewModel so ProductViewModel should expose public PackagingViewModel Packaging property
ProductViewModel should accept all model-related stuff (perhaps some services, model entity, etc) and then initialize all other child view models.
I created a new entity object and bound it to controls in another window (edit window). After modifying and saving I assigned a new entity object into the one in the main window. The old entity object is bound into a datagrid, now I want the datagrid to display the data that I had modified and saved.
ObjectContext.Refresh Method (RefreshMode, Object) seems to be what I want but I don't know how to use it correctly.
In short :
I have a main window with datagrid displaying the whole data of the table. Users can pick one row and edit it in a edit window. After saving, the datagrid should display what has been modified.
Your best bet here is to use an ObservableCollection as your data source for the datagrid instead of the query.
And look at implementing INotifyPropertyChanged interface in your Customer class.
The ObservableCollection is initially populated by the database query. User changes are made to elements within the ObservableCollection and once complete you then just need to trigger transferring the changes to wherever you originally obtained your list of Customer objects
By doing this changes made both to the collection of Customers and to individual Customer objects (if present within the datagrid) will be automatically updated for you.
edit
I must admit that I'm a bit rushed to offer up any code at the moment, but here's a pretty good article that explains how to use ObservableCollections and classes that implement INotifyPropertyChanged. It also has code examples, which although in VB.NET should give you enough of an idea to get started.
In effect you separate your code into distinct layers UI (View), business logic (View Model) and data layer (Model where your entity framework resides).
You bnd your datagrid to the ObservableCollection type property in your Customers class and your edit csutomer window is bound to as instance of your Customer class.
I have a columned listview who's items I would like to store in an XML file.
What's the best way to go about loading, saving and adding items?
best way is to use MVVM :), that way your View simply represents the data in the UI. Actual DomainModel/BusinessObject resides outside your View.
And then you can use number of persistance methods:
XML Serialization
ORM (Object Relation Mapping), which will persist/save the BusinessObject into Database and back
Step by step way:
Create/Define your BusinessObject(DomainModel, i.e. Person class)
Use DataTemplate to Bind to Collection from your ListView
In your ViewModel, you can than say PersonCollection.Save/Load etc
Long title, hope it makes sense. Can't seem to figure out how I would implement this. Or if my approach is even somewhat on track with best practices for this kinda stuff b/c i'm still working on mvvm and probably not using it correctly yet.
I have a simple viewmodel in an application i'm working on and it contains two properties which point to datamodel collections.
public ChuteGroupsModel Groups { get; set; }
public WaveStatusModel Waves { get; set; }
Each one of these datamodels contains all the data I need for a tabpage in my tabcontrol of my MainWindow. One tabpage is a grid of statistic data and the other page is a custom user control that visualizes a physical "working" area.
I decided today that I would like to display some of the statistic values from the grid (# of items, # remaining, etc) inside of the tooltips of my custom user controls. My two collections are only connected by an ID# field.
So, basically I need to figure out a way to filter/bind to my "Waves" collection according to the ID# property of the current element that is bound to "Groups".
The obvious easy answer here is to modify my sql view to include the additional fields which would make them immediately available for me to bind to in my application.
Since all of the data I wish to visualize already exists, I can't help but feel that changes to sql are a bit unnecessary and that some easy solution exists to help me gather these values out of my other collection.
Can anyone provide any suggestions of what I could attempt to do? If my question does not make sense I can try to re-state it with more code snippets and hopefully that will help.
Perhaps some more information about your ViewModel / View binding would be helpful. As given, if your ViewModel exposes properties of both Groups and Waves to your View, and the View containing the TabControl is bound to your ViewModel, I see no reason why controls on either TabPage couldn't be bound to properties sourced from either data model.
To put it another way, the ViewModel can abstract away the separate data-model collections from the View, building, for example, its own collection of objects which expose the properties of both a ChuteGroup and its associated WaveStatus. The View can then be bound to that collection, and access the properties of both objects.