xaml 方法:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="grid1">
<!--xaml中设置渐变效果-->
<!--<Grid.Background>
<LinearGradientBrush>
<GradientStopCollection>
<GradientStop Offset="0" Color="Black" />
<GradientStop Offset="0.6" Color="white" />
</GradientStopCollection>
</LinearGradientBrush>
</Grid.Background>-->
</Grid>
</Window><Window x:Class="WpfApplication1