This is a migrated thread and some comments may be shown as answers.

How to set label background with opacity from windows8palette

3 Answers 808 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lukasz
Top achievements
Rank 1
Lukasz asked on 11 Aug 2016, 12:34 PM

I am trying to use AccentColor for label background with opacity:

<telerik:Label>
    <telerik:Label.Background>
        <SolidColorBrush Color="{telerik:Windows8Resource ResourceKey=AccentBrush}" Opacity="0.1"/>
    </telerik:Label.Background>
</telerik:Label>

This gives me an error: "#FF25A0DA" is not a valid value for property 'Color'.

How to get a valid color value in xaml?

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 15 Aug 2016, 09:00 AM
Hi Lukasz,

The error is occurring because you are assigning a SolidColorBrush as a Color property of a SolidColorBrush. The brush resources of our themes (e.g. AccentBrush) are already SolidColorBrushes.

You can achieve the desired result by getting the color value of the AccentBrush ( I could guess it is #FF25A0DA ) and change its opacity. The structure of the ColorValue is [AA][RR][GG][BB], where AA is alpha. So you can redefine the Color as #1925A0DA (as 19 is 10% of FF).

Or in a similar way you are setting it now with Opacity as a separate property, only assign a color to the Color setter, not a SolidColorBrush reference.
<telerik:Label>
    <telerik:Label.Background>
        <SolidColorBrush Color="#FF25A0DA" Opacity="0.1"/>
    </telerik:Label.Background>
</telerik:Label>

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Lukasz
Top achievements
Rank 1
answered on 29 Aug 2016, 08:32 AM

Thanks for your reply. Can I somehow avoid using hardcoded value and get color value from resources? I am using Windows8 theme and I want my label to use color from theme and just add opacity to it.

Thanks,

Ɓukasz

0
Martin
Telerik team
answered on 31 Aug 2016, 09:04 AM
Hello Lukasz,

You can add you the Window.Resources a custom brush, that you can define using the theme palette:

public MainWindow()
{
    Color win8Accent = Windows8Palette.Palette.AccentColor;
    byte opacity = (byte)((double)win8Accent.A * 0.5);
    Color MyColor = Color.FromArgb(opacity, win8Accent.R, win8Accent.G, win8Accent.B);
    var CustomBrush = new SolidColorBrush(MyColor);
 
    InitializeComponent();
 
    this.Resources.Add("CustomBrush", CustomBrush);
}

And refer it as a {DynamicResource CustomBrush}.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
Lukasz
Top achievements
Rank 1
Answers by
Martin
Telerik team
Lukasz
Top achievements
Rank 1
Share this question
or