WPF (Windows Presentation Fundation)

Главная | Исходники | Книги | Ссылки |

Использование изображения из XAML файла, как фона.

В окне Solution Explorer создаем папку Dictionary в которой создаем файл Background_main.xaml типа ResourceDictionary, который будет описывать фон.

  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2.   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3.   <Canvas x:Key="Background_main">
  4.     <Path Fill="#ff000000" Data="F1 M 841.890,595.275 L 0.000,595.275 L 0.000,0.000 L 841.890,0.000 L 841.890,595.275 Z"/>
  5.     <Path Data="F1 M 265.910,218.277 C 265.910,169.332 223.865,129.655 172.000,129.655 C 120.135,129.655 78.090,169.332 78.090,218.277 C 78.090,267.222 120.135,306.898 172.000,306.898 C 223.865,306.898 265.910,267.222 265.910,218.277 Z">
  6.       <Path.Fill>
  7.         <RadialGradientBrush MappingMode="Absolute"
  8.                    GradientOrigin="172.733,217.234"
  9.                    Center="172.733,217.234"
  10.                    RadiusX="81.912"
  11.                    RadiusY="81.912">
  12.           <RadialGradientBrush.GradientStops>
  13.             <GradientStop Offset="0.00" Color="#ff0d4976"/>
  14.             <GradientStop Offset="0.41" Color="#ff06243b"/>
  15.             <GradientStop Offset="1.00" Color="#ff000000"/>
  16.           </RadialGradientBrush.GradientStops>
  17.           <RadialGradientBrush.Transform>
  18.             <MatrixTransform Matrix="1.146,0.000,0.000,1.082,-26.038,-16.750" />
  19.           </RadialGradientBrush.Transform>
  20.         </RadialGradientBrush>
  21.       </Path.Fill>
  22.     </Path>
  23.   </Canvas>
  24. </ResourceDictionary>
* This source code was highlighted with Source Code Highlighter.
Наш основной файл Window1.xaml выглядит так:
  1. <Window x:Class="WpfTestBackground.Window1"
  2.   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.   Title="Window1" Height="300" Width="300">
  5.   <Window.Resources>
  6.     <ResourceDictionary Source="Dictionary/Background_main.xaml" />
  7.   </Window.Resources>
  8.   <Grid >
  9.     <Grid.Background>
  10.       <VisualBrush Visual="{StaticResource Background_main}" />
  11.     </Grid.Background>
  12.   </Grid>
  13. </Window>
* This source code was highlighted with Source Code Highlighter.

 


Главная | Программирование | Покер | Фотография | Разное
© Андрей Семёнов, 2009
Hosted by uCoz