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!
Related
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.
The documentation just shows that an xml configuration property exists for visibility, but doesn't show how to use it. The documentation for the command line equivalent shows:
–visibility[=”...”]
Provide a comma-separated list of visibility scopes to parse.
This parameter may be used to tell phpDocumentor to only parse public properties and methods, or public and protected.
There are private properties that are showing up in my documentation and I'd like to hide them. I've tried <visibility>public</visibility> but it appears to have no effect.
Update
I'm currently using the default template. It both lists the private methods and shows a "Private Methods" section on the template.
If that --visibility flag is not working, it must be a bug. Then again, it's possible that some output templates display the three visibility view toggles even if the document generation execution was run with only "public" being enabled.
In the resulting docs you've generated with a particular template, are you still seeing all three visibility buttons showing? If so, enable the private and protected buttons, then see if any private/protected properties/methods actually do become visible. It might be that you are getting only public things documented, but just still seeing the private/protected toggle buttons in the view.
This works for me --visibility="public"
The visibility element works. Put inside
<parser>
<visibility>public</visibility>
<target>docs/api</target>
</parser>
I have a ViewModel which contains a Boolean property which tells you if the user has authenticated or not.
I have a WrapPanel which is bound to a collection of profiles. The DataTemplate for these profiles has an icon - a closed padlock for when the user is not authenticated and an open one for when the user is authenticated. Ideally these would be bound to the Boolean on the ViewModel but the DataContext for the templates is the individual profile objects.
I have tried,
Setting the Source selector in the binding as specified here although it appear Windows Phone 7 does not support x:Reference
I tried also the Inversion of Control(?) method detailed here (but containerLocator was not found on my object)
I tried applying a Style.Trigger but these are not supported in Windows Phone 7
I also tried accessing the XAML elements in the code behind and updating programmatically on event triggers, however I could not get a handle on the Image element inside the DataTemplate
Edit after comment: WP7 does not support style triggers. But if anyone is looking for this answer on following versions I let the reply below:
I would use a Style Trigger as seen here to update the icon Source property on the fly - as part of the style of your DataTemplate so you would get a hold of your Image.
One way I found that works based on an answer by Damian Antonowicz but does not implement the full inversion of control method that he uses, is as follows,
Create a partial class which resolves to your view-model instance under your view-model namespace, e.g.
public partial class ViewModelInstanceLocator
{
public AppViewModel AppViewModel // Or whatever the type of your view-model is ...
{
get
{
return App.VM; // Or wherever your view model instance is ...
}
}
}
Define the other half of the class in your XAML page as a resource so that it can be referred to as a static resource, I did this in my App.xaml so that it could be referred to everywhere,
<ResourceDictionary>
<viewmodel:ViewModelInstanceLocator x:Key="ViewModelInstanceLocator" />
...
</ResourceDictionary>
You may need to include the relevant namespace if there is not already a reference to your view-model namespace e.g. at the top,
xmlns:viewmodel="clr-namespace:MyAppNamespace.ViewModel"
Finally to bind to the view-model as follows,
{Binding AppViewModel.SomeProperty, Source={StaticResource ViewModelInstanceLocator}}
The binding updates as usual just as if the view-model instance had been referred to through the DataContext. However, it does not work with design-time data.
Say I have a list of Action objects, which corresponds to a Ember model. Each has a few properties (timestamps) and a detail attribute, which can can recursively contain more details (arbitrarily deep nesting). You can think of the details as nested lists.
I want to write a UI that allows easy editing (auto completion of values, easy copy and paste, reorder elements, etc) of the detail for any Action object.
Right now, my DetailView template will recursively render additional DetailViews:
{{#if view.content.hasChildren}}
{{#each child in view.content.children}}
{{#DetailView contentBinding=child}}
{{/each}}
{{#else}}
{{#EditDetailView contentBinding=view.content.value}}
{{/if}}
So each DetailsView corresponds to a node in the Details object tree.
But I am unclear how to add controllers to the mix -- there is additional state I need to store / functionality to implement (e.g., transforming values from the Detail object for display in the DetailsView; handling events for inserting/deleting/reordering elements; changing the structure of the Details tree) that belongs neither in the model nor the view.
Ideally I would have a DetailsController serving as a proxy a Details per DetailsView. Can I dynamically instantiate controllers and set up their contents within a view template? My understanding of the new Ember Router is to setup controllers and outlets in in a given route; however, that doesn't seem to apply here because no routing is being done at all. All suggestions / insight about how to handle recursive controllers / views / routes welcome.
I've taken a look at EmberJS Nested Views and Controllers, but that proposes I have a single ArrayController for all Details, even across Actions ... this would not preserve the tree structure of the nested details either.
I've also looked at Recursive view in handlebars template not working after upgrading to Ember 0.9.6 but the solution doesn't say anything about controllers.
** UPDATE Feb 20, 2013 **
API documentation for the {{control}} helper is now available here. It warns that "The control helper is currently under development and is considered experimental."
To enable it, set ENV.EXPERIMENTAL_CONTROL_HELPER = true before requiring Ember.
** UPDATE Feb 3, 2013 **
A new helper {{control}} has been added to ember, implementing the Reusable Views proposal. So to have a DetailsController proxy a Details per DetailsView you can just:
{{control 'detail' child}}
See the {{control}} tests for example
Ideally I would have a DetailsController serving as a proxy a Details per DetailsView. Can I dynamically instantiate controllers and set up their contents within a view template?
Typically the way to do this would be via the handlebars {{render}} helper, which renders a template with an appropriate view and controller. Unfortunately you cannot use {{render}} to insert the same template more than once, so it cannot be used within an {{each}} block.
There was a lengthy discussion on the topic recently. See: Non-Singleton Controller Discussion!
Two solutions were proposed. The first involves adding an itemControllerClass property to ArrayController. If this property was set, the ArrayController would automatically wrap new contents in the specified class. This was added to ember a few weeks ago and takes care of most use cases, where you have a flat-list of items and want each to be wrapped in a proxy.
The second proposal, Reusable Views, allows you to provide a controller class to a view.
{{view UI.Calendar dateBinding="post.startDate" controllerClass="App.CalendarController"}}
This would create an instance of App.CalendarController for each UI.Calendar widget, which would be tied to the lifecycle of the widget. As of today this has not been implemented. See {{view}} should have an option to create a controller! for the latest status.
So AFAIK there is not a good way to accomplish this for the use case you outlined. Meantime, binding data to the view:
{{view App.DetailView contentBinding="child"}}
and then having some logic in the view itself seems reasonable. If/when Reusable View support is added to master you can pull that logic up into the controller.
See: https://github.com/emberjs/ember.js/issues/1766
Does any one know a way to find out unused views in project ? with Resharper or without it.
any idea which is easier than writing down all the views and go through all controllers and check manually is appreciated :)
Thanks
With ReSharper you can right-click a Razor view and Find Usages, but you'd have to go through manually and repeat for all views (unless you can hook into ReSharper's API and automate it).
The problem with views of course is that they're late-bound based on a convention defined in the view engine, in the case of the default RazorViewEngine it looks for a corresponding view in ~/Views/{Controller}/{Action} and ~/Views/Shared/{Action}. So it's difficult to tell at design or compile time which views, partials and templates are never used.
You might approch it from the opposite angle: find which views are being used. Then diff this list against all views in the project, evaluate the results (manually and with ReSharper Find Usages) and confirm they're really not being used before finally removing them.
To find the views being used you could customise the RazorViewEngine to log every time it loads a view with CreateView and FindPartialView, e.g.
public class LoggingRazorViewEngine : RazorViewEngine
{
protected override IView CreateView(
ControllerContext controllerContext,
string viewPath,
string masterPath)
{
LogManager.GetLogger("").Debug(viewPath);
return base.CreateView(controllerContext, viewPath, masterPath);
}
}
Configure it in global.asax.cs
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new LoggingRazorViewEngine());
Then extract a list of logged unique view paths to compare against your project's views. Bit of effort involved, but possibly worth if if you've got lots of unused views cluttering up the project.
You could rename one of the suspicious views and compile... if some controller is using it you will get errors :)
Don't know of any "built in" feature to look for unused views.