In "Prism 6" how to bind viewmodel to model - prism

Please explain to me how to use this method:
AutoWireViewModelChanged(object view, Action<object, object> setDataContextCallback)
What is the best way to bind view and viewmodel?

You don't need to call that method from code to bind view and viewmodel. You simply add this line to the xaml of your view and the binding will happen automatically. If you want to read deeper into this topic, check this paragraph in the official documentation.
ViewModelLocator.AutoWireViewModel="true"
You can check this sample on the Prism GitHub repository to see a working example.

Related

How can I use 2 models in a single view?

I'm currently working on a homepage where I am showing the 'latest hauls' and 'latest finds' they are both separate models ofcourse.
Currently I am only showing the 5 latest hauls since I use the HaulController#getWelcome Controller so I can access $haul->title etc.
How would I be able to also access $finds->title?
Thanks for the help!
You can share a model to a view by using it inside controller function -
View::share('subadmin', App\Models\SubAdmin::class);
You can call the model in your view like
{{ \App\Model::function() }}
So you can have {{ App\Model::orderBy('created_at', 'desc')->limit(5)->get() }}
You have a couple of options.
Option 1: A combined model and one view.
To do this create a new ViewModel and have LatestHauls and LatestFinds as properties on this model. You could set these properties in the controller.
On your view simply navigate down the viewmodel to the appropriate properties.
Option 2: Extend the above solution to use partial views. Create a partial view for each model. On the parent view call each partial view. This might be considered a better solution but option 1 will get you started.

Try to bind partial view for different classes

I try to use one partial view for all classes implementing particular interface
#{Html.RenderPartial("_PaymentItem", Model.RentItem);}
#{Html.RenderPartial("_PaymentItem", Model.EquipmentItem);}
#{Html.RenderPartial("_PaymentItem", Model.InterestItem);}
#{Html.RenderPartial("_PaymentItem", Model.ForfeitItem);}
#{Html.RenderPartial("_PaymentItem", Model.SupplyItem);}
All PaymentItems are part of the model. After I post the page all payment items bind the values from the last rendered partial view. I assume the problem is that the partial view generates same ids and names for each invoke. How can i bypass this ?
Thanks in advance, I'll appreciate any help.
Have you tried casting your model properties to the particular interface?
EDIT:
What I mean is to specify the model
e.g.
#model IViewM
on the first line of your _PaymentItem file.

Where did ViewLocationExpanderContext.IsPartial go?

In Core MVC if you want the razor view engine to look for views in places other than the default locations then a new ViewLocationExpander can be added in the ConfigureServices method in the startup.cs like so
services.Configure<RazorViewEngineOptions>(options => {
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
Where the ViewLocationExpander class implements IViewLocationExpander. That class typically has access to the ViewLocationExpanderContext, and in RC1 that context contained an IsPartial property. This property was useful if the location expander wanted to specify different view locations for partial views than regular views.
I see that in RC2 this IsPartial property is gone. However, I do see that there is a IsMainPage property but I can't find any documentation on it.
Does anyone know if the property basically just the inverse of the old IsPartial property?
Yes, the IsMainPage property is as you've said - the inverse of IsPartial. As Pranav has pointed out in the comments, you can see the commit and reasoning for the change here.
Glad to see I'm not the only one that was caught out by this change!

MVC JavaFx methods

if I want to add for example the mouse event "setOnMouseEntered" to my code and I already have a viewer, controller, model and main. Where do I put this method in?
Because if I search for examples, this methos is written in the start-method. In my case it would be in the main class? Actually have kind of a scene styler in the viewer.
Thanks!
do you search for something like this?
https://github.com/StefanHeimberg/javafx8-spielwiese/tree/master/example-fullscreen-fade/src/main/java/example/menubar.
in the menubar.fxml (VIEW) i used the onAction="#handleImage2LongRunningAction" and fx:controller="example.menubar.MenubarPresenter" (CONTROLLER)
then on the presenter i called some service (MODEL / Business Logic)...

Additional options for MarionetteJS CollectionView

I have no idea what am I missing here but I'm not able to pass additional parameter to a CollectionView, like so:
View definition is very basic:
class UI.Elements extends App.Views.CollectionView
itemView: UI.Element
And then instantiated with these options:
getUIsView: (uiobjects, itemView) ->
options =
collection: uiobjects
variationView: itemView
new App.VariationsApp.UI.Elements options
With this code the view is being created fine, except the variationView is no where to be found. From backbone documentation:
When creating a new View, the options you pass — after being merged into any default options already present on the view — are attached to the view as this.options for future reference
But my CollectionView doesn't have options property on itself.
Really, I don't have any idea what am I doing wrong. Any help would be greatly appreciated because I'm stuck.
Any parameter you provide your view that aren't recognized as Backbone/Marionette options will be attached to this.options within the view. So you should have access to the variationView by accessing this.options.variationView.
If you need to access that information in the template, you need to pass it along by writing a serializeData function.
You can see an example of this in practice here: https://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/common/views.js

Resources