开发者

Is it possible to apply Gradient to a Background Image in Silverlight?

开发者 https://www.devze.com 2023-02-06 21:14 出处:网络
I want to apply some gradient to my image how can I ach开发者_开发技巧ieve that? ThanxYou could host your image within a Border, applying the gradient to the border background:

I want to apply some gradient to my image how can I ach开发者_开发技巧ieve that?

Thanx


You could host your image within a Border, applying the gradient to the border background:

<Border>
    <Border.Background>
        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
            <GradientStop Color="Red" Offset="0" />
            <GradientStop Color="Blue" Offset="1" />
        </LinearGradientBrush>
    </StackPanel.Background>
    <Image Source=..your image source .." />
</Border>

This assumes that your image has some opaque regions which will show the gradient beneath it.


In the gradient you can use one or more colours. Any it is very easy to set the gradient using either VS2010 or expression blend. The following is the sample code of a two-colour gradient with blue and white.

<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

<LinearGradientBrush.RelativeTransform>                         <CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="-90"/>
    </LinearGradientBrush.RelativeTransform>
    <GradientStop Color="#FFB6D3F9"/>
    <GradientStop Color="#FFFDFDFD" Offset="1"/>
    </LinearGradientBrush>
0

精彩评论

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

关注公众号