I'm working on a XAML-based Windows Phone 8.1 project. My MainPage has a Pivot control, the first item of which is designed to be a "dashboard" of some sort, combining multiple kinds of data such as events and to-dos.
For this particular purpose I have an Event and a To-do model classes (not the actual name, but you get the idea), as I am using MVVMLight to run the show.
I have currently set up a ListView in a pivot item in MainPage.xaml. I was wondering how can I make it work such that all items with objects Event and To-do are at one single pivot item.
I've looked around and found CompositeCollection, but it's only on WPF, not on WinRT yet. I tried dealing with Midgard.CompositeCollection but the data doesn't show up, and I don't understand how can I style these independent kinds of data differently.
Are there any techniques on combining two datasets together on one set of lists but will be styled separately? Is ListView the correct control for dealing with multiple kinds of data, or is there something else?
I'm still quite new to this field; apologies if this is a basic concept I can't quite grasp yet.
Thank you!
There is a way and it is quite simple. Make both Event and To-do inherit from the same base class (could be empty) and create an ObservableCollection of this base type (can also be object if you do not want to create a separate class). Add both Event and To-doobject to this ObservableCollection.
Bind the ListView to this ObservableCollection. Now comes the tricky part. You need to create a DataTemplateSelector. For a compete guide, see http://blog.kulman.sk/using-different-data-templates-with-gridview-in-windows-8-apps/ (this articles is for GridView but it works the same for ListView).
Related
I'm developing a tree menu using Om Next by nesting multiple instances of the same component ((defui Tree...). I can recursively build the tree by passing different properties, so the initial rendering is fine.
But, re-rendering items upon the state change is problematic since they share the same query and the params. But, if I can have different query parameters in different component instances they will be served with appropriate properties.
My understanding is, the query and the parameters are linked to the Component rather the individual instances. Therefore, trying to update parameters using om-next/set-query! didn't work here.
What is the idiomatic way of handling such a scenario?
Can we do a workaround with om/factory?
(Please pardon me if I'm suffering from a misunderstanding of fundamentals here.)
Let's say I have a bunch of kittens. Perhaps I have a KittenViewModel. I want to show it as a kitten card in a card view, but also as broken down into columns in a list view. Does MvvmCross support binding the KittenViewModel to multiple views? Should I have multiple ViewModels that refer back to a single model?
Disclaimer: I know that I am replying to an old question which you may well have forgotten; this is for posterity. Also, I have limited understanding of the MVVM design pattern. I remember reading somewhere that Views and ViewModels are typically in 1-to-1 correspondence, so the conventional answer is probably "You shouldn't do that. Reconsider your design."
With that being said, I recently struggled with this for a while before coming up with a very simple solution that operates under the following assumptions: (1) you wish to use the exact same instance of a ViewModel in two separate Views; (2) for whatever reason, you cannot use a DataTemplateSelector to determine which View to use; and (3) you do not mind creating multiple Views for the same ViewModel.
The solution is to define separate data templates for the KittenViewModel as resources for whatever controls you are going to use to display the data. For example, if you have created a KittenCardView user control and intend to display it in a ContentControl, you can set the DataTemplate in a ContentControl resource, something like:
<ContentControl>
<Control.Resources>
<DataTemplate DataType="{x:Type viewmodel:KittenViewModel}">
<view:KittenCardView/>
</DataTemplate>
</Control.Resources>
</ContentControl>
The KittenColumnView (or whatever you call it) would be handled similarly. You may find it helpful to define one of the Views as a Window or App resource if typically use one and only need the other in special circumstances.
Continuing to work on my port of a CakePHP 1.3 app to 3.0, and have run into another issue. I have a number of areas where functionality varies based on certain settings, and I have previously used a modular component approach. For example, Leagues can have round-robin, ladder or tournament scheduling. This impacts on the scheduling algorithm itself, such that there are different settings required to configure each type, but also dictates the way standings are rendered, ties are broken, etc. (This is just one of 10 areas where I have something similar, though not all of these suffer from the problem below.)
My solution to this in the past was to create a LeagueComponent with a base implementation, and then extend that class as LeagueRoundRobinComponent, LeagueLadderComponent and LeagueTournamentComponent. When controllers need to do anything algorithm-specific, they check the schedule_type field in the leagues table, create the appropriate component, and call functions in it. This still works just fine.
I mentioned that this also affects views. The old solution for this was to pass the league component object from the controller to the view via $this->set. The view can then query it for various functionality. This is admittedly a bit kludgy, but the obvious alternative seems to be extracting all the info the view might require and setting it all individually, which doesn't seem to me to be a lot better. If there's a better option, I'm open to it, but I'm not overly concerned about this at the moment.
The problem I've encountered is when tables need to get some of that component info. The issue at hand is when I am saving my add/edit form and need to deal with the custom settings. In order to be as flexible as possible for the future, I don't have all of these possible setting fields represented in the database, but rather serialize them into a single "custom" column. (Reading this all works quite nicely with a custom constructor and getters.) I had previously done this by loading the component from the beforeSave function in the League model, calling the function that returns the list of schedule-specific settings, extracting those values and serializing them. But with the changes to component access in 3.0, it seems I can no longer create the component in my new beforeMarshal function.
I suppose the controller could "pass" the component to the table by setting it as a property, but that feels like a major kludge, and there must be a better way. It doesn't seem like extending the table class is a good solution, because that would horribly complicate associations. I don't think that custom types are the solution, as I don't see how they'd access a component either. I'm leaning towards passing just the list of fields from the controller to the model, that's more of a "configuration" method. Speaking of configuration, I suppose it could all just go into the central Configure data store, but that's always felt to me like somewhere that you only put "small" data. I'm wondering if there's a better design pattern I could follow that would let the table continue to take care of these implementation details on its own without the controller needing to get involved; if at some point I decide to change from the serialized method to adding all of the possible columns, it would be nice to have those changes restricted to the table class.
Oh, and keep in mind that this list of custom settings is needed in both a view and the table, so whatever solution is proposed will ideally provide a way for both of them to access it, rather than requiring duplication of code.
I am working on a project with Xpages.I wanted to know how to make the representation of a class diagram to my project.Notes is a documentary database so no relationnal.How I could represent my entities?
In Domino, documents are merely evidence of the existence of people, processes, and physical entities (products, offices, inventory, etc.). Ideally, your classes should model those things.
For instance, you might have classes like Employee, with properties like firstName, lastName, hireDate; maybe Asset, with properties like category, model, serialNumber; or perhaps Request, with properties like status, requester, dateApproved. Eventually the values of each of these properties might be stored as item values in Domino documents, but defining these first as attributes of classes allows you to follow a simple pattern to develop your application:
Use your class structure to rapidly define the nature of each "thing" your application interacts with, without worrying yet what each must look like or how and where the data will ultimately be stored.
Once you have these classes defined, you can bind visual components on an XPage (such as input fields like edit boxes and radio button groups) very easily using the #{dataSource.propertyName} syntax.
When these two steps are done, all you have left to do is to add two methods to each of these entity classes: one to write the data, and another to retrieve it.
Following this approach makes it very easy to rapidly build the application, but also protects your user interface from changes in how you wish the data to be stored. Initially, each object might represent a single document. As the application grows in either complexity or adoption, however, you may decide to segregate the data such that many documents are created to represent a single entity. Or at some point you might even decide to store some, or all, of the data outside of Domino (DB2, SQL, etc.). If your XPage components are bound to properties of these entity classes, all you need to do to change how or where the data is stored is to update the two methods you created in step 3 of the above list: alter how you write and retrieve the data. Your actual XPage design elements don't need to change at all.
Depends how you look at it. You can always think of following relation: Notes Form <-> Java POJO and Notes View <-> Java Collections.
See http://www.pipalia.co.uk/notes-development/rethinking-xpages-part-two/ for some tips on using Java world standards when working with xPages.
I'm trying to move to a Model/ViewModel/View architecture and got stuck when trying to push selection dialogs to this pattern. I'd like to separate retrieving a list of choices (business/presentation logic) and the actual displaying/choosing mechanism (view) to re-use the former with different views (e.g. ComboBox vs. modal dialog).
How would a ViewModel for such a selection task look like? Or am I trying to hard, and I should implement this in the View only?
Do you mean that you would like to use the implementation to retrieve list?? If so, I think you can create a service class in the application layer and reuse the functionality..