Set theme color into SolidColorBrush resource

4 posts, 1 answers
  1. Kamran
    Kamran avatar
    23 posts
    Member since:
    Nov 2011

    Posted 05 Nov 2018 Link to this post

    I am trying to set current theme (Fluent) AlternativeBrush color into SolidColorBrush resource. I am facing error #FFF2F2F2' is not a valid value for property 'Color'. 

    Everything is working fine, but only problem when I want to define SolidColorBrush resource from Fluent theme. This resource will be used in other templates.

    For reference following is sample code what I am doing now

     

    <SolidColorBrush Color="{telerik:FluentResource ResourceKey=AlternativeBrush}" x:Key="AlternativeBrush"/>
  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    657 posts

    Posted 07 Nov 2018 Link to this post

    Hello Kamran,

    Thank you for the provided code snippet. 

    First, please allow me to say that you do not have to define a separate brush in order to use this resource. For example you can just use it like so:
    <Border Background="{telerik:FluentResource ResourceKey=AlternativeBrush}" Width="100" Height="100" />

    That said, it is not possible do define the brush in xaml, however you can define it in code like so:
    var brush = new SolidColorBrush(Telerik.Windows.Controls.FluentPalette.Palette.AlternativeColor);

    and later add it to the Resources collection of your application/window. 

    Hope this helps.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Kamran
    Kamran avatar
    23 posts
    Member since:
    Nov 2011

    Posted 07 Nov 2018 in reply to Vladimir Stoyanov Link to this post

    Thank you Vladimir Stoyanov's for your response. I am following the same practices as you suggested. So whenever I define style/ template in resource I set background by telerik:Resource. But I have scenario where I don't want to define style for each item. For example in my case for some specific ellipse and rectangle i use fill/ stroke color to be from current theme.

    finally I got some snippet from implicit theme styles. Please suggest me if I am doing wrong. but it works fine for me. Here is example

        <SolidColorBrush x:Key="BasicSolidColorBrush" Color="{Binding Source={x:Static telerik:FluentPalette.Palette}, Path=BasicSolidColor}"/>
     
     
    <Grid Grid.Column="0" Background="{DynamicResource BasicSolidColorBrush}" >
    .......
    </Grid>

     

     

  4. Answer
    Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    657 posts

    Posted 08 Nov 2018 Link to this post

    Hello Kamran,

    Thank you for the additional information.

    Indeed I have missed that you can also define the brush in xaml in the way that you have done. Your current approach is fine and if you find it suitable, you can continue using it.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top