Опубликован: 23.01.2009 | Доступ: свободный | Студентов: 1541 / 149 | Оценка: 4.33 / 4.22 | Длительность: 13:08:00
Специальности: Программист
Лекция 5:

Рисование

Таким образом, получается серия цветов, напоминающая радугу (спектр). В табл. 5.5 приводятся различные примеры использования градиента.

Таблица 5.5. Элемент LinearGradientBrush, серия цветов, атрибут Сolor
Код Вид в браузере
5.5.1
<Canvas
xmlns="http://schemas.microsoft.com/
client/2007"
xmlns:x="http://schemas.microsoft.com
/winfx/2006/xaml"
Width="150" Height="150"
Background="White"
x:Name="Page">

<Rectangle Width="150"
 Height="150" >
    <Rectangle.Fill>
        <LinearGradientBrush>
            <GradientStop Color="
Blue" Offset="0" />
            <GradientStop Color="
Red" Offset="0.2" />
    <GradientStop Color="
Orange" Offset="0.3" />
            <GradientStop Color="Yellow" 
Offset="0.4" />
    <GradientStop Color="
Green" Offset="0.5" />
            <GradientStop Color="DeepSkyBlue" 
Offset="0.6" />
    <GradientStop Color="Blue" 
Offset="0.7" />
            <GradientStop Color="Purple" 
Offset="0.8" />
    <GradientStop Color="White" 
Offset="1" />
        </LinearGradientBrush>
    </Rectangle.Fill>
</Rectangle>
</Canvas>

Описание
Градиент содержащий серию цветов
Код Вид в браузере
5.5.2
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="150" Height="150"
Background="White"
x:Name="Page">


    <Ellipse Width="150" 
Height="150" >
       <Ellipse.Fill>
         <LinearGradientBrush>
              <GradientStop Color="Blue" 
Offset="0" />
              <GradientStop Color="Red" 
Offset="0.2" />
              <GradientStop Color="Orange" 
Offset="0.3" />
              <GradientStop Color="Yellow"
 Offset="0.4" />
              <GradientStop Color="Green" 
Offset="0.5" />
              <GradientStop Color="DeepSkyBlue" 
Offset="0.6" />
              <GradientStop Color="Blue" 
Offset="0.7" />
              <GradientStop Color="Purple" 
Offset="0.8" />
              <GradientStop Color="White" 
Offset="1" />
              </LinearGradientBrush>
            </Ellipse.Fill>
          </Ellipse>
</Canvas>

Описание
Применение градиента к окружности
Код Вид в браузере
5.5.3
<Canvas
xmlns="http://schemas.microsoft.com/
client/2007"
xmlns:x="http://schemas.microsoft.com/
winfx/2006/xaml"
Width="250" Height="150"
Background="White"
x:Name="Page">
<TextBlock
  Canvas.Top="5"
  FontFamily="Arial Bold"
  FontSize="90"
  FontWeight="Bold">
  Текст
  <TextBlock.Foreground>
    <LinearGradientBrush StartPoint="0,0" 
EndPoint="1,1">
<GradientStop Color="Blue" 
Offset="0" />
<GradientStop Color="Red"
 Offset="0.2" />
<GradientStop Color="Orange"
 Offset="0.3" />
<GradientStop Color="Yellow" 
Offset="0.4" />
<GradientStop Color="Green" 
Offset="0.5" />
<GradientStop Color="DeepSkyBlue" 
Offset="0.6" />
<GradientStop Color="Blue" 
Offset="0.7" />
<GradientStop Color="Purple"
 Offset="0.8" />
<GradientStop Color="White" 
Offset="1" />

    </LinearGradientBrush>
  </TextBlock.Foreground>

</TextBlock>
</Canvas>

Описание
Заливка градиентом текста
Код Вид в браузере
5.5.4
<Canvas
xmlns="http://schemas.microsoft.com/
client/2007"
xmlns:x="http://schemas.microsoft.com
/winfx/2006/xaml"
Width="150" Height="150"
Background="White"
x:Name="Page">

<Rectangle Width="130" Height="130" 
Canvas.Left="10" Canvas.Top="10"
 Fill="Black"/>
        <Rectangle Width="150" Height="
150" Opacity="0.8">
            <Rectangle.Fill>
                <LinearGradientBrush >
                    <GradientStop Color="Blue" 
Offset="0" />
                    <GradientStop Color="White" 
Offset="1" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
</Canvas>

Описание
Прозрачность для всего прямоугольника, заполненного градиентом
Код Вид в браузере
5.5.5
<Canvas
xmlns="http://schemas.microsoft.com/
client/2007"
xmlns:x="http://schemas.microsoft.com/
winfx/2006/xaml"
Width="150" Height="150"
Background="White"
x:Name="Page">

<Rectangle Width="130" 
Height="130" Canvas.Left="10" 
Canvas.Top="10" Fill="Black"/>
        <Rectangle Width="150" 
Height="150" >
            <Rectangle.Fill>
                <LinearGradientBrush >
                    <GradientStop Color="Blue" 
Offset="0" />
                    <GradientStop Color="Transparent" 
Offset="1" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
</Canvas>

Описание
Градиентная прозрачность