Mapp view Button text color

Hello, is there a way to set the textcolor of a mapp-view button, i want to change the color of the text depending a certain value
fe if a value is 0 the color must be white , if the value is 1 the textcolor must be red if the value is 3 the color must be green.

with regards
Sven

Hello,

You can implement this using style and event.

Please check the attached sample project file. (AS4.12.7 & mappView5.24.4)
ButtonColor.zip (118.1 KB)

Recording2025-05-03204949


  1. Create a styles file for custom button style.

  1. Register the id of the style you added to the .styleset file.(1)
  2. Copy the default style of the button. And paste it into the style file you added. As an example, I changed the names to ButtonTextRed and ButtonTextGreen. (2)
  3. Change the textColor to the color (rgb) you want. (3)

  1. Connect the variable to opcUa.Event that you want to change the color of the text to. (1)
  2. Enter the conditions under which you want to change the text color. (2)
    • newValue means the value that is updated every time.
  3. Complete the Widgets.Action to change the style of the button. (3)

Best Regards,

4 Likes

Thank you for your advice, i will try to add it to my project !

1 Like

Hello,

i managed to get your program working and understand what you do,
but in my program it looks no Theme gets loaded;

all the buttons are configured with their L&F with the properties,
can that be the problem?

does AS modify the default css/xml file with these modifications?

with regards
Sven

If you set anything in the properties of the widget instance, they will override the styling coming from themes.

There are probably two reasons why the event doesn’t work.

  1. Theme not added in visualization. (Configuration view - mappView - *.vis)
  • The files in Logical view - mappView are just implemented objects.
  • To apply themes, events, images, etc., you must register the object in the *.vis file in Configuration view - mappView.
  1. Text colors were mapped directly to widget properties.
  • As @tommi.piiparinen said, the options entered directly into the properties are not styled. (If not the default, it appears in bold.)
  • If the default text color for your theme is white, add a black style. (eg, ButtonTextBlack)
    And add an option for black to widget.Action.