Can I set separate each button's fore color?

Hi

I prepared toolbar:

@foreach (var Item in @myBar)

{

Text=@(Item.Text) TooltipText=@(Item.TooltipText)

HtmlAttributes=@(Item.HtmlAttributes)>

}


and set background color:

ToolbarItem sItem;

Dictionary d;

string c;

foreach (InfoRec infoRec in infoList)

{

sItem = new ToolbarItem();

sItem .Text = infoRec.Code;

sItem .TooltipText = infoRec.Name;

sItem .Id = infoRec.Code;

c = "background: " + infoRec.Color + "!important;";

d = new Dictionary()

{

{ "style" , c }

};

sItem .HtmlAttributes = d;

myBar.Add(sItem );

}

It works only for background. How to set separate each button's color?

Regards

Maciej


3 Replies

RM Ruksar Moosa Sait Syncfusion Team April 19, 2022 02:02 PM UTC

Hi Maciej,


To get the font color of the button, you can use the default CssClass="@Item.CssClass" property of the toolbar and apply the CSS to it like the below code snippet.


List<ToolbarData> ToolbarItems = new List<ToolbarData>()

    {

        new ToolbarData

        {

        Text = "Cut",

        TooltipText = "Cut",

        CssClass = "primary"

        },

        new ToolbarData

        {

        Text = "Copy",

        TooltipText = "Copy",

        CssClass = "secondary"

        },       

    };



<style>

 

    . primary {

        background-color: orange;

    }

     .primary .e-tbar-btn-text{

         color: green !important;

    }

    .secondary{

        background-color: yellow;

    }

    .secondary .e-tbar-btn-text{

         color: red !important;

    }

 

</style>


Output:


Kindly try the attached sample and let us know if this meets your requirement.

                                                 

Regards,

Ruksar Moosa Sait


Attachment: ToolbarTextColor_b5513b44.zip


MA Maciej April 21, 2022 09:35 AM UTC

Thank you for answer.


You set the background of the buttons and the color of the font. 

Can I also set the button color?

And can I do it dynamically - creating a color in the program, not in a style file?


Regards,

Maciej



RM Ruksar Moosa Sait Syncfusion Team April 22, 2022 12:11 PM UTC

Hi Maciej,


No. The button color can be set only through the CSS classes and not possible programmatically.


Regards,

Ruksar Moosa Sait


Loader.
Up arrow icon