Binding to CSS classes in XML views through the "class" attribute is not directly supported by UI5. However, a workaround using custom data can be implemented:
Add custom data to your control, setting the writeToDom property and binding it to the desired expression:
<code class="xml"><Text class="myControl"> <customData> <core:CustomData writeToDom="{= myExpression }" key="green" value="" /> </customData> </Text></code>
Define a CSS selector that targets the control based on the custom data value. For example:
<code class="css">.myApp .sapText.myControl[data-green] { /* ... */ }</code>
In the following example, the "green" class is added to the
<code class="xml"><Text class="myControl"> <customData> <core:CustomData writeToDom="{= ${myTable>enabled} ? 'green' : 'red' }" key="green" value="" /> </customData> </Text></code>
<code class="css">.myApp .sapText.myControl[data-green] { color: green; } .myApp .sapText.myControl[data-red] { color: red; }</code>
The above is the detailed content of How to Bind to CSS Classes in UI5 XML Views Using the \'class\' Attribute?. For more information, please follow other related articles on the PHP Chinese website!