Sound Player Action demo

image_pdfimage_print
   
 

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Button>A Button With Sounds
    <Button.Triggers>
      <EventTrigger RoutedEvent="Button.Click">
        <EventTrigger.Actions>
          <SoundPlayerAction Source="click.wav"/>
        </EventTrigger.Actions>
      </EventTrigger>
      <EventTrigger RoutedEvent="Button.MouseEnter">
        <EventTrigger.Actions>
          <SoundPlayerAction Source="hover.wav"/>
        </EventTrigger.Actions>
      </EventTrigger>
    </Button.Triggers>
  </Button>
</Canvas>

   
     


Play audio through event trigger

image_pdfimage_print
   
 
<Window x:Class="SoundAndVideo.SoundPlayerTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SoundPlayerTest" Height="300" Width="300">
    <StackPanel>
        <Button>
        <Button.Content>Play Through Wrapper</Button.Content>
        <Button.Style>
          <Style>
            <Style.Triggers>
              <EventTrigger RoutedEvent="Button.Click">
                <EventTrigger.Actions>
                  <SoundPlayerAction Source="test.wav"></SoundPlayerAction>
                </EventTrigger.Actions>
              </EventTrigger>
            </Style.Triggers>
          </Style>
        </Button.Style>
      </Button>
    </StackPanel>
</Window>

   
     


Nested Span elements

image_pdfimage_print


   
      
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Center" VerticalAlignment="Center">


<TextBlock>
  <Span FontFamily="Cambria">
    This uses <Span FontWeight="Bold">a
    <Span FontStyle="Italic">mixture</Span> of</Span> styles.
  </Span>
</TextBlock>


</Page>

   
    
    
    
    
    
     


SpeechSynthesizer demo

image_pdfimage_print


   
  
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Speech Synthesis" Height="300" Width="300"
    >
    <Grid>
        
    </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Speech.Synthesis;

namespace WpfApplication1
{
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();

            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            PromptBuilder promptBuilder = new PromptBuilder();

            promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut);
            promptBuilder.AppendText("sounds better than WPF.");

            // Pause for 2 seconds
            promptBuilder.AppendBreak(new TimeSpan(0, 0, 2));
            
            promptBuilder.AppendText("The time is");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToString("hh:mm"), SayAs.Time);
            
            promptBuilder.StartVoice("this is a test");
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndVoice();
            
            promptBuilder.AppendText("Do it faster!");
            
            promptBuilder.StartVoice("Hi");
            promptBuilder.StartStyle(new PromptStyle(PromptRate.ExtraFast));
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndStyle();
            promptBuilder.EndVoice();
 
            synthesizer.SpeakAsync(promptBuilder);
        }
    }
}

   
    
     


Speech Synthesis demo

image_pdfimage_print


   
  

<Window x:Class="SoundAndVideo.SpeechSynthesis"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SpeechSynthesis" Height="300" Width="300">
    <StackPanel>
      <TextBox Name="txtWords" ScrollViewer.HorizontalScrollBarVisibility="Visible" TextWrapping="Wrap">Hello, world</TextBox>
      <Button Margin="5" Grid.Row="1" Click="cmdSpeak_Click">Speak</Button>
      <Button Margin="5" Grid.Row="2" Click="cmdPromptTest_Click">Prompt Test</Button>
    </StackPanel>
</Window>
//File:Window.xaml.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Speech.Synthesis;

namespace SoundAndVideo
{
    public partial class SpeechSynthesis : System.Windows.Window
    {
        public SpeechSynthesis()
        {
            InitializeComponent();
        }

        private void cmdSpeak_Click(object sender, RoutedEventArgs e)
        {
            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            synthesizer.Speak(txtWords.Text);
        }

        private void cmdPromptTest_Click(object sender, RoutedEventArgs e)
        {
            PromptBuilder prompt = new PromptBuilder();
            
            prompt.AppendText("A");            
            prompt.AppendBreak(TimeSpan.FromSeconds(2));
            prompt.AppendText("A ", PromptEmphasis.Reduced);
            PromptStyle style = new PromptStyle();
            style.Rate = PromptRate.ExtraSlow;
            style.Emphasis = PromptEmphasis.Strong;
            prompt.StartStyle(style);
            prompt.AppendText("B ");
            prompt.EndStyle();            
            prompt.AppendText("C?");          
            
            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            synthesizer.Speak(prompt);
            
        }
    }
}

   
    
     


SolidColorBrush described using 3-digit hexadecimal notation: amount of red, green, and blue in the color.

image_pdfimage_print


   
 

            
<Window x:Class="WpfApplication1.ShapesWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShapesWindow" Height="160" Width="400">
      <Window.Resources>
        <Style TargetType="{x:Type Rectangle}">
          
          <!-- Gives all the rectangles in this panel a white stroke. -->
          <Setter Property="Stroke" Value="White"/>
          <Setter Property="StrokeThickness" Value="1"/>
        </Style>
      </Window.Resources>
    <Canvas>
      <Rectangle Width="50" Height="50" Fill="#00F" />
    </Canvas>
</Window>

   
     


SolidColorBrush described using 6-digit hexadecimal notation.

image_pdfimage_print


   
 

<!--The first pair of digits describes the amount of red in the color,
the next pair describes the amount of green,
and the final two digits describes the amount of blue.
-->
            
<Window x:Class="WpfApplication1.ShapesWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShapesWindow" Height="160" Width="400">
      <Window.Resources>
        <Style TargetType="{x:Type Rectangle}">
          
          <!-- Gives all the rectangles in this panel a white stroke. -->
          <Setter Property="Stroke" Value="White"/>
          <Setter Property="StrokeThickness" Value="1"/>
        </Style>
      </Window.Resources>
    <Canvas>
      <Rectangle Width="50" Height="50" Fill="#0000FF" />

    </Canvas>
</Window>