Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a LinearGradientBrush in another LinearGradientBrush?

I'm trying to use one LinearGradientBrush in the Definition of another LinearGradientBrush. But I've no idea weather this would even work, and if it works, I need to know how.

For Example:

    <LinearGradientBrush x:Key="ComboBoxFocusBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFFDEEB3" Offset="0"/>
        <GradientStop Color="#FFFBF2CD" Offset="1"/>
        <GradientStop Color="#FFFCE48A" Offset="0.5"/>
        <GradientStop Color="#FFFBE388" Offset="0.75"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="FilterPopupTitleBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#B45988" Offset="0.75"/>
        //Code here to use ComboBoxFocusBackgroundBrush
        <GradientStop Color="#990088" Offset="0.75"/>
    </LinearGradientBrush>

thanking you in anticipation for your answers

Edit: To get things a bit more clear in the example I want to use "ComboBoxFocusBackgroundBrush" in the "FilterPopupTitleBrush" as a "template".So that I've the same color gradient in both brushes without a copy of the "<GradientStop...>"-tags

like image 582
Tokk Avatar asked Sep 14 '10 12:09

Tokk


2 Answers

You can share the list of gradient stops between multiple brushes, like this:-

<GradientStopCollection x:Key="MyGradient">
    <GradientStop Color="#FFFDEEB3" Offset="0"/> 
    <GradientStop Color="#FFFBF2CD" Offset="1"/> 
    <GradientStop Color="#FFFCE48A" Offset="0.5"/> 
    <GradientStop Color="#FFFBE388" Offset="0.75"/> 
</LinearGradientBrush> 

<LinearGradientBrush x:Key="ComboBoxFocusBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"
   GradientStops="StaticResource MyGradient}" /> 

<LinearGradientBrush x:Key="FilterPopupTitleBrush" EndPoint="0.5,1" StartPoint="0.5,0"
    GradientStops="{StaticResource MyGradient}" /> 

Now you can vary the EndPoint, StartPoint and other properties create different variants of the same basic gradient.

You can even supply the same set to RadialGradientBrush.

like image 158
AnthonyWJones Avatar answered Sep 18 '22 18:09

AnthonyWJones


Sharing another way of doing this, you don't need to create a separate collection, you can also reuse the existing brush like

<LinearGradientBrush x:Key="FilterPopupTitleBrush" GradientStops="{Binding GradientStops, Source={StaticResource ComboBoxFocusBackgroundBrush}}"/>

This way of creating a custom brush based on existing brush will be helpful specially when you want to extend predefined themes like Telerik themes, where it would not be good approach to change the XAML from telerik.

like image 29
Muhammad Ummar Avatar answered Sep 17 '22 18:09

Muhammad Ummar