Document Styles

image_pdfimage_print


   
     


<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="title">
    <Page.Resources>

        <Style TargetType="{x:Type Paragraph}" x:Key="Normal">
            <Setter Property="TextIndent" Value="0.25in" />
        </Style>

        <Style TargetType="{x:Type Paragraph}" x:Key="ChapterHead">
            <Setter Property="TextAlignment" Value="Center" />
            <Setter Property="FontSize" Value="16pt" />
        </Style>

    </Page.Resources>
    <FlowDocumentReader>
        <FlowDocument>
            <Paragraph Style="{StaticResource ChapterHead}">
                 Chapter I
            </Paragraph>
            <Paragraph Style="{StaticResource ChapterHead}">
                 Chapter Head
            </Paragraph>
            <Paragraph Style="{StaticResource Normal}">
                this is a test
            </Paragraph>
            <Paragraph Style="{StaticResource Normal}">
                ...
            </Paragraph>
        </FlowDocument>
    </FlowDocumentReader>
</Page>

   
    
    
    
    
     


Multiple Sounds

image_pdfimage_print


   
     

<Window x:Class="SoundAndVideo.MultipleSounds"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MultipleSounds" Height="300" Width="300">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
      </Grid.RowDefinitions>
      <MediaElement x:Name="media1" Volume="0.25"></MediaElement>
      <MediaElement x:Name="media2" Volume="1"></MediaElement>
      <Button>
        <Button.Content>Click.</Button.Content>
        <Button.Triggers>
          <EventTrigger RoutedEvent="Button.Click">
            <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <MediaTimeline Source="c:song.mp3" Storyboard.TargetName="media1"></MediaTimeline>
              </Storyboard>
            </BeginStoryboard>
            </EventTrigger.Actions>
          </EventTrigger>
        </Button.Triggers>
      </Button>

      <Button Grid.Row="1">
        <Button.Content >wav</Button.Content>
        <Button.Triggers>
          <EventTrigger RoutedEvent="Button.Click">
            <EventTrigger.Actions>
              <BeginStoryboard>
                <Storyboard>
                  <MediaTimeline Source="c:song.wav" Storyboard.TargetName="media2"></MediaTimeline>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger.Actions>
          </EventTrigger>
        </Button.Triggers>
      </Button>
    </Grid>
</Window>

   
    
    
    
    
     


Animated Text Transform

image_pdfimage_print


   
     

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock Text="XAML" FontSize="144pt" FontFamily="Arial Black"
               HorizontalAlignment="Center" VerticalAlignment="Center"
               RenderTransformOrigin="0.5 0.5">

        <TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform x:Name="xformScale" />
                <RotateTransform x:Name="xformRotate" />
            </TransformGroup>
        </TextBlock.RenderTransform>

        <TextBlock.Triggers>
            <EventTrigger RoutedEvent="TextBlock.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="xformScale"
                                         Storyboard.TargetProperty="ScaleX"
                                         From="1" To="-1" Duration="0:0:3" 
                                         AutoReverse="True"
                                         RepeatBehavior="Forever" />

                        <DoubleAnimation Storyboard.TargetName="xformRotate"
                                         Storyboard.TargetProperty="Angle"
                                         From="0" To="360" Duration="0:0:5" 
                                         RepeatBehavior="Forever" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </TextBlock.Triggers>
    </TextBlock>
</Page>

   
    
    
    
    
     


Discrete Point Jumps

image_pdfimage_print


   
     

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Path Fill="Red">
        <Path.Data>
            <EllipseGeometry x:Name="elips" RadiusX="24" RadiusY="24" />
        </Path.Data>
    </Path>

    <Canvas.Triggers>
        <EventTrigger RoutedEvent="Canvas.Loaded">
            <BeginStoryboard>
                <Storyboard TargetName="elips" TargetProperty="Center">
                    <PointAnimationUsingKeyFrames Duration="0:0:4"
                                                  RepeatBehavior="Forever">
                        <DiscretePointKeyFrame KeyTime="0:0:0" Value="288 96" />
                        <DiscretePointKeyFrame KeyTime="0:0:3" Value="96 288" />
                    </PointAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Canvas.Triggers>
</Canvas>

   
    
    
    
    
     


Resource Lookup

image_pdfimage_print


   
     

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Orientation="Horizontal">

    <StackPanel.Resources>
        <SolidColorBrush x:Key="brushText" Color="Blue" />
    </StackPanel.Resources>

    <StackPanel>
        <StackPanel.Resources>
            <SolidColorBrush x:Key="brushText" Color="Red" />
        </StackPanel.Resources>

        <Button HorizontalAlignment="Center" 
                VerticalAlignment="Center" 
                Margin="24"
                Foreground="{StaticResource brushText}">
            Button with Red text
        </Button>
    </StackPanel>

    <StackPanel>
        <Button HorizontalAlignment="Center" 
                VerticalAlignment="Center" 
                Margin="24"
                Foreground="{StaticResource brushText}">
            Button with Blue text
        </Button>
    </StackPanel>

</StackPanel>

   
    
    
    
    
     


Horizontal Linear Gradient and GradientStop

image_pdfimage_print


   
     

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Microsoft.Samples.Graphics.RectangleExample"
    WindowTitle="Example">
  <Canvas>

    <Rectangle Width="150" Height="100" Grid.Row="2" Margin="5">
      <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
          <GradientStop Color="Blue" Offset="0"/>
          <GradientStop Color="White" Offset="1" />
        </LinearGradientBrush>
      </Rectangle.Fill>
    </Rectangle>
    <TextBlock Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="5">Horizontal Linear Gradient</TextBlock>

  </Canvas>
</Page>

   
    
    
    
    
     


Change Fill

image_pdfimage_print


   
   

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
  mc:Ignorable="d"
  x:Class="PaintDrawExamples.ChangeFill" 
  Width="640" Height="480">

  <StackPanel.Resources>
    <Storyboard x:Key="OnLoaded"/>
  </StackPanel.Resources>

  <StackPanel.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
      <BeginStoryboard x:Name="OnLoaded_BeginStoryboard" Storyboard="{DynamicResource OnLoaded}"/>
    </EventTrigger>
  </StackPanel.Triggers>
  <Path d:LastTangent="0,0" Width="300" Height="82" x:Name="myShape" RenderTransformOrigin="0.5,0.5" Stretch="Fill" Data="M268,209 L134,209 147,249 250,290 z">
    <Path.RenderTransform>
      <TransformGroup>
        <TranslateTransform X="0" Y="0"/>
        <ScaleTransform ScaleX="1" ScaleY="1"/>
        <SkewTransform AngleX="0" AngleY="0"/>
        <RotateTransform Angle="0"/>
        <TranslateTransform X="0" Y="0"/>
      </TransformGroup>
    </Path.RenderTransform>
    <Path.Fill>
      <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
        <GradientStop Color="#11111111" Offset="0"/>
        <GradientStop Color="#FFFFFFFF" Offset="1"/>
      </LinearGradientBrush>
    </Path.Fill>
  </Path>
</StackPanel>
//File:Window.xaml.cs

using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace PaintDrawExamples
{
  public partial class ChangeFill
  {
    public ChangeFill()
    {
      this.InitializeComponent();
      this.MouseDown += new MouseButtonEventHandler(MouseDownHandler);
    }

    private void MouseDownHandler(object sender, MouseButtonEventArgs e)
    {
      LinearGradientBrush brush = (LinearGradientBrush)this.myShape.Fill;
      brush.GradientStops[0].Color = Color.FromRgb(0,0,0);
    }
  }
}