开发者

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"/>
        <GradientSto开发者_如何学Cp 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜