Defining Opacity Using a Resource Dictionary

1 Answer 42 Views
Styling
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
Neil N asked on 04 Jul 2024, 08:24 PM

How do I declare these properties in a resource dictionary instead of code? I can't quite get the proper syntax.

FluentPalette.Palette.DisabledOpacity = 0.5; 
FluentPalette.Palette.ReadOnlyOpacity = 0.4; 

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 05 Jul 2024, 06:28 AM

Hello Neil,

You can see how to do this in XAML in the following article.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 06 Jul 2024, 09:40 PM

I've read that article probably a dozen times before posting here.  It only has examples dealing with colours. Can you please answer my exact question? "This can be done by re-defining the resource in XAML and using the same x:Key as the original resource used by the palette." is unhelpful if there aren't examples showing how to figure out the XAML syntax for properties like I listed above.
Martin Ivanov
Telerik team
commented on 08 Jul 2024, 07:02 AM

The example below shows how to define the DisabledOpacity and ReadOnlyOpacity in XAML. This will override the default resources of the palette. The code snippet is the same as the one in the Changing Palette Settings in XAML section of the linked article, but it defines System.Double values instead of SolidColorBrush.

Anyway, we will update the article in order to be more clear on how to define also numeric resources and also we will add some description about determining the resource name. Basically, if you need to set properties of the pallete of the Fluent theme, you will need to use the FluentResourceKey markup extension class. If you need the Windows11 theme, use Windows11ResourceKey. The property names are almost the same, but the ResourceKey extensions use Brush objects instead of Color objects, which requries change in the property naming. For example, instead of AccentColor (as defined in the palette), the color name in the ResourceKey class will be AccentBrush.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:sys="clr-namespace:System;assembly=netstandard"             
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <sys:Double x:Key="{x:Static telerik:FluentResourceKey.DisabledOpacity }">0.5</sys:Double>
    <sys:Double x:Key="{x:Static telerik:FluentResourceKey.ReadOnlyOpacity  }">0.5</sys:Double>
</ResourceDictionary>

I also attached a sample project showing this. I hope it helps.

 

Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 09 Jul 2024, 03:52 PM

Thank  you very much!
Tags
Styling
Asked by
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Martin Ivanov
Telerik team
Share this question
or