LinearGradientBrush 使用

    <Grid>
        <Rectangle Width="200" Height ="100" Name="rcTest">
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,1" EndPoint="1,0"> 
                    <GradientStop Color="Orange" ></GradientStop>
                    <GradientStop Color="Red" Offset="0.15">
                        </GradientStop>             
                    <GradientStop Color="Blue" Offset="0.5" >
                    </GradientStop>
                    <GradientStop Color="Yellow" Offset="0.75" />
                    <GradientStop Color="Aqua" Offset="1"></GradientStop>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Button Height="26" Margin="86,24,94,0" Name="btnUpdate" VerticalAlignment="Top" Background="BlanchedAlmond" Click="btnUpdate_Click">Button</Button>
    </Grid>
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            LinearGradientBrush linear = new LinearGradientBrush();
            linear.StartPoint = new Point(0.5, 0);
            linear.EndPoint = new Point(0.5, 1);
            GradientStop gs1 = new GradientStop() { Color = Colors.Yellow };
            GradientStop gs2 = new GradientStop() {Color = Colors.Green, Offset = 0.5};
            GradientStop gs3 = new GradientStop() { Color = Colors.Pink, Offset = 1.0 };
            linear.GradientStops.Add(gs1);
            linear.GradientStops.Add(gs2);
            linear.GradientStops.Add(gs3);
            rcTest.Fill = linear;
        }

 

posted @ 2017-03-21 11:04  lxa520  Views(470)  Comments(0)    收藏  举报