How could I achieve something similar as WPF's ContentPresenter + UI Template in MvvmCross/Droid?
A region on the screen will display a ViewModel. Depending on the ViewModel, a Layout View (DataTemplate) will be used to present the ViewModel.
note: This is not about lists
Thanks!
Related
I have a blazor component which binds to a collection of objects to render a list of cards. This works great as it is.
What I would like to enable is to declaratively define the list of cards as razor syntax. Something like the following:
<MyListComponent>
<Card>1st Card - Card-specific contents here</Card>
<Card>2nd Card - Card-specific contents here</Card>
<Card>3rd Card - Card-specific contents here</Card>
</MyListComponent>
Can this be achieved?
Note that i have created a datagrid/listview component which use RenderFragment "templates" for the Columns and Rows. But seems like this is different from what i am trying to achieve here.
Is it possible to set element data context in MvvmCross?
Suppose I have:
<RelativeLayout>
<TextView/> <TextView/>
</RelativeLayout>
and I'd like to set RelativeLayout data context to viewmodel property.
XAML equivalent of:
<Grid DataContext="{Binding someProperty}">
<TextBlock/> <TextBlock/>
</Grid>
You can't currently do this directly in a single axml file in MvvmCross at present.
However:
You can use MvxFrameControl to load a sub-axml file (a bit like an include) and then set the DataContext for everything inside that sub-view
MvvmCross is open source - so you can extend and adapt it...
What is the process of adding a widget to a page dynamically? Essentially I have an "Add Widget" button on a view which is hooked up to a function addWidget() in the viewmodel. Basically, when someone hit's the button, I want to dynamically create an instance of a durandal widget and add it to the DOM. My code looks like this:
var addWidget = function () {
var parent = $('<div></div>')
.attr('data-bind', 'widget: { kind:\'myWidget\'}')
.appendTo($('#dashboardContent'))
.get(0);
return widget.create(parent, { id: 'Hello World' });
}
I can see in the browser developer tools that the widget HTML (view) is added to the DOM, but it's not rendering the widget, and activate is not being called on the widget.
What am I missing?
From the looks of it you are trying to use jQuery to add the widget to the DOM. Just thinking out loud the problems are that A: jQuery has no idea what activate is (that is handled by Durandal's router) and B: Nothing will get bound properly. If you are trying to add widgets, why not create an observableArray that contains widgets and just add them into there? That may sound a bit silly, and I am not sure the best way to approach it, but basically it could look like this
In your view model -
var myWidgets = observableArray();
myWidgets.push(someObjectsToComposeTheWidget);
And in your view -
<ul data-bind="foreach: myWidgets">
<li data-bind="widget: {kind:'yourWidget', items: somethingGoesHere, headerProperty:'name'}">/div>
<ul>
This will allow you to dynamically add and display the widgets without having to get messy and use jQuery to display things.
Hi guys im creating/adding elemnts in my item renderer but from some reason you cant access their specific properties, you can only change the general properties. I created a LABEL component but when i do LabelName.font , nothing happens, its like flex doesnt recognize that this is a LABEL. Here is my code
var mylabel:Label = new Label()
mylabel.font
when i do "mylabel.someProperty" it only shows the general properties of any component, but how can i change other properties like font,color,size etc..
Thanks ahead [=
Fonts are defined as styles in Flex, not propeties, so you need to use the setStyle method to update it. (Not my favorite part about Flex.) For example:
myLabel.setStyle('fontFamily', newFont)
There is a difference between MXML and ActionScript in this. In MXML, styles of a component are shown as if they were properties, when they are really not. To set the fontFamily of your label in AS3 code, for example, you would use
myLabel.setStyle("fontFamily", "Arial")
I'm using a taxonomy part in one of my custom content types, and using the shape tracer, I was able to create a custom view template for that control (Fields.Contrib.TaxonomyField.cshtml).
When I shape trace the element on the page, under template it indeed shows my custom template exactly as I have it on the external file:
#using Orchard.Utility.Extensions;
#using Orchard.ContentManagement;
#{
var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;
string name = #Model.ContentField.Name;
}
#if (Model.Terms.Count > 0) {
#(new HtmlString( string.Join(", ", terms.Select(t => Html.ItemDisplayLink(Html.Encode(t.Name), t.ContentItem ).ToString()).ToArray()) ))
}
<div>TEST TEXT</div>
However, when I tab over to the actual outputted HTML, it is showing the standard, built in template, and isn't using my customizations.
<p class="taxonomy-field">
Coffee Shop
</p>
According to the shape tracer, it is using my custom template:
Shape Fields_Contrib_TaxonomyField
Active Template
~/Themes/Continuum/Views/Fields.Contrib.TaxonomyField.cshtml
Display Type Detail
this feels like a bug... everything looks like it's wired up correctly... is there something else I need to do to use my custom view template for taxonomy?
Many thanks!
I figured out the problem. Turns out there was another template created (likely by accident) which was url-specific:
Fields.Contrib.TaxonomyField-url-venues.cshtml
that's the url I was on, and this had the default template still in it. After deleting it, it finally used my custom template.
User error, sorry!!