I'm trying to develop a PRISM WPF application where I am going to have two or more views depending on the same ViewModel. At first I thought of using Unity to do an injection through the view's constructor and within the constructor set the DataContext. That idea was dismissed by the team because they want nothing in the code-behind. Moreover, the views are using a ViewModelLocator that is Autowired to the ViewModel. So then my only other thought doing a Module with a single view, but then how do I go about sharing the same ViewModel between modules if I'm using Unity IOC? Any ideas with some kind of example?
Don't share ViewModels instances between views. Just load data as you need it. But if you must shoot yourself in the foot there are many ways to do it. The easiest would be to register your ViewModel as a singleton in your container.
Related
So I have seen a few of these scripts in unity and I am wondering how I can recreate it in my own scripts?
So I have a script the when a object is clicked, it will call a function on another script. I want to be able to pass arguments and much more but the Inspector got messy with a bunch of toggles, int fields etc.
Is there any way to recreate this sort of thing?
Not as much the Event type but the little function box instead. If that makes sense :)
Thanks!
The box you showed in that screenshot is an Event Trigger. There isn't any way that I know of that lets you separate the UI object from this underlying type. So there isn't a way to just draw the delegate box.. However, you can make a class based off of EventTrigger and then you can extend EventSystemEditor.
You can also make a class derived from UnityEvent in this fashion and it will show up with a function delegate box the way you wanted it to.
However, again, that just won't get you a drawing method that draws the function/delegate box for you. I don't know of a single way of getting Unity3D to let you do that.
You can check the entire list of GUI drawing methods:
https://docs.unity3d.com/ScriptReference/EditorGUILayout.html
https://docs.unity3d.com/ScriptReference/EditorGUI.html
But it's just not there.
I know that some people have managed to achieve similar effects with Inspector wizardy, recreating a similar aspect and functionality. I know FullInspector can do delegates in its inspector and you could check its source code to figure out how, but it could end up being a lot of work. Specifically serializing the delegate is hellish, so if you want it to serialize, I wouldn't even bother. I suggest finding a different path of minimal resistance.
Here's an alternative:
You can collect the methods in the class you're targeting via reflection and present them in a dropdown menu. Then once a method is selected you can again use reflection to see what parameters that method requires and use GUI functions to draw the appropriate fields required to receive those parameters from user input.
It's definitely possible, but again, I think that will take quite a lot of time to elaborate and you're better off finding a way of satisfying your requirements without this level of Editor GUI shenanigans.
I am still learning swift so please don't mind if my approach is wrong--
So i am trying to create a game and i have upto 4 players
I thought having a singular container view to render the views for them would be more efficient than to have to create separate views for each of them(but i cant figure out how to render them differently right now but intend to)
Is my approach to this wrong or should i keep going?
Layers in MVVM
How many layers in MVVM project and what we put in each layer ?
Do we have Poco also ?
Three layers
Model (Data base)
View-Model (Methodes proprites commands )
View the UI without a behind code all code is in View Model
This MSDN paper on MVVM should answer your question with regard to the logical layering of an MVVM solution. Pocos may exist depending upon your Model complexity.
http://msdn.microsoft.com/en-us/library/gg405484%28v=pandp.40%29.aspx
Do someone has an Idea, how to implement a Layout in RCP,
where the Views would look like Tabs and appear nested?
The Tabs should have all the advantages of Views - can be dragged to the desktop to become a detached view, be tiled near each other, rearranged etc.
On the picture the views: View4 and View5 are nested into View1.
In my experience, something like this will not be easy - there's likely going to be a lot of custom coding in your future. I'll try to cover this more from a high level architecture standpoint, since there'll be a lot of details you'll need to figure out specific to your requirements and strengths.
There's two ways you can go about this I think:
1. write a view extension where the contents of that view are other views.
This would be less work up front, but might be harder to get view rearrangement to work. Based on your mockup, this means View1 is an instance of this view, and is responsible for rendering the tab controls for View4/View5, and telling those views to render their content. You can probably look at MultiPageEditorPart for some inspiration, though you'll probably want to render the tabs a bit nicer.
In this case, your subviews will likely plug in specifically to their parent view. Drag and drop support within the view wouldn't be too bad, though pulling them out of the view would involve a bit of work. This article provides a basic intro to drag-and-drop; google can provide the rest.
2. write a custom presentation to render your views in this way.
This one might be a bit more work up front to learn about how the presentation layer works, but once that is done, it will probably be easier to get all the features you're looking for. See this article for an introduction to presentation layers.
In this case, all your views will be treated by the plugin system as top level views - your presentation layer decides where to render the areas for the view contents. I've used presentation layer for something similar to this, but in my case, the views were all statically positioned. That said, since everything is a regular view, you should be able to re-use the existing drag-and-drop functionality to rearrange views with a lot less effort than the other option.
I am new to iOS platform and i heard about MVC archtecture.
To draw a circle i just create a separate UIView class and override the drawRect: and able to do this.
But now i want to rebuild the same project using MVC architecture.The main aim is to separate my Model part from View & Controller part.So that i can extend my project.
So how can i do this?
Any sample application for reference?
I'm not sure what you want to separate. Drawing a circle would generally fit into the "View" part of the MVC architecture, which is what you have already done. Code that would, for instance, change the colour of the circle would live in the "Controller" part, which on iOS is a UIViewController. If you had something storing information on what the circle looked like (i.e. size, colour, etc.), that could be considered part of the model, and can be stored in its own class, pulled in by the view controller and passed to the view when it is neede.
Here is a link that may help.
http://www.bit-101.com/blog/?p=1969
As for the model side of things, Core Data is a technology that can help.
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP40001075
The separation would be the drawing code in drawRect and the size and location in a model with a controller getting the circle attributes from the model and requesting the drawing and passing the attributes to the view. The model might be another class or an API supplied class such as an NSDictionary.
By creating a separate model if there were multiple circles the controller could make multiple draw requests, one per model circle. Or there could be multiple views that the circle(s) would be drawn in or different representations such as a text list of the circles attributed in one view and graphic circles in another.
Many patterns seem trivial and not particularly useful in the trivial case yet in a real-world program work very well.