Data binding of CSS class attribute in XML view

z00bs picture z00bs · Jan 8, 2015 · Viewed 7.2k times · Source

How can I bind the value of the CSS class attribute of a XML fragment to a model property within another XML view?

The following snipped works fine

<core:Fragment fragmentName="com.foo.bar.Fragment" type="XML" class="important"/>

and should be changed to something like

<core:Fragment fragmentName="com.foo.bar.Fragment" type="XML" class="{itemStatus}"/>

where {itemStatus}should be bound to model property.

Any help appreciated!

Answer

10littleOrcs picture 10littleOrcs · Jan 12, 2015

Unfortunately, it is indeed not possible to bind the class attribute, as Qualiture already mentioned. However, there is a workaround using custom data, which can be bound, written to the DOM and hence also used for styling purposes. You can see an example here in the documentation: Writing Data to the HTML DOM as DATA-* Attribute

Hope that helps