"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Bind to CSS Classes in UI5 XML Views Using the \"class\" Attribute?

How to Bind to CSS Classes in UI5 XML Views Using the \"class\" Attribute?

Published on 2024-11-12
Browse:283

How to Bind to CSS Classes in UI5 XML Views Using the \

Binding in Control with "class" Attribute

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:

Using Custom Data for Binding

  1. Add custom data to your control, setting the writeToDom property and binding it to the desired expression:

  2. Define a CSS selector that targets the control based on the custom data value. For example:

    .myApp .sapText.myControl[data-green] { /* ... */ }

Example

In the following example, the "green" class is added to the control when its "enabled" property is true:

.myApp .sapText.myControl[data-green] { color: green; }
.myApp .sapText.myControl[data-red] { color: red; }

Considerations

  • While binding to custom data allows for manipulating CSS styles, it is important to consider the following:
  • Custom CSS styles should be used cautiously, as they can impact UI consistency and maintenance.
  • Explore alternative solutions, such as using semantic classes or custom formatters, before resorting to custom CSS.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3