RadialGradientBrush GradientOrigin


   
  


<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      WindowTitle="StackPanel vs. DockPanel">
  <Grid Width="175" Height="150">
    <Rectangle Grid.Row="1" Grid.Column="0"  Width="100" Height="100" 
      StrokeThickness="4" Margin="4">
      <Rectangle.Fill>
        <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" 
          RadiusX="0.5" RadiusY="0.5">
          <GradientStop Color="Black" Offset="0" />
          <GradientStop Color="Gray" Offset="0.45" />
          <GradientStop Color="Black" Offset="0.85" />
        </RadialGradientBrush>
      </Rectangle.Fill>
      <Rectangle.Stroke>
        <SolidColorBrush Color="Blue"/>
      </Rectangle.Stroke>
    </Rectangle>
  </Grid>
</Page>

   
    
     


RadialGradientBrush examples and Define GradientStop in Resource


   
  
<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
    <Window.Resources>
    <GradientStopCollection x:Key="myGradientStops">
      <GradientStop Offset="0.0" Color="Blue" />
      <GradientStop Offset="0.4" Color="Black" />
      <GradientStop Offset="0.5" Color="White" />
      <GradientStop Offset="0.6" Color="Black" />
      <GradientStop Offset="0.7" Color="Blue" />
    </GradientStopCollection>
    
    </Window.Resources>
    <Rectangle Width="175" Height="90" Stroke="Black">
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}"></RadialGradientBrush>
      </Rectangle.Fill>
    </Rectangle>

</Window>

   
    
     


RadialGradientBrush Opacity from 1 to 0


   
  

<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
    <Window.Resources>
        <GradientStopCollection x:Key="myGradientStops">
      <GradientStop Color="Blue" Offset="0.0" />
      <GradientStop Color="Black" Offset="0.5" />
      <GradientStop Color="Transparent" Offset="1.0" />
    </GradientStopCollection>
    </Window.Resources>
    <StackPanel>
    <Rectangle Width="100" Height="50" Stroke="Black" StrokeThickness="1">
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}" Opacity="1.0" />
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Width="100" Height="50" Stroke="Black" StrokeThickness="1" >
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}" Opacity="0.75" />
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Width="100" Height="50" Stroke="Black" StrokeThickness="1">
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}" Opacity="0.5" />
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Width="100" Height="50" Stroke="Black" StrokeThickness="1">
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}" Opacity="0.25" />
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Width="100" Height="50" Stroke="Black" StrokeThickness="1">
      <Rectangle.Fill>
        <RadialGradientBrush GradientStops="{StaticResource myGradientStops}" Opacity="0" />
      </Rectangle.Fill>
    </Rectangle>
    </StackPanel>
</Window>

   
    
     


Indeterminate ProgressBar


   
  

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ProgBar.Window1"
    Title ="ProgressBar"
    Width="500">

  <StackPanel>
    <Button Content="One" Click="MakeOne"/>
    <StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" >
      <StatusBarItem>
        <TextBlock>StatusBar</TextBlock>
      </StatusBarItem>
    </StatusBar>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;



namespace ProgBar
{

    public partial class Window1 : Window
    {
        
        private void MakeOne(object sender, RoutedEventArgs e)
        {
            sbar.Items.Clear();
             Label lbl = new Label();
             lbl.Background = new LinearGradientBrush(Colors.Pink, Colors.Red, 90);
             lbl.Content = "Indeterminate ProgressBar.";
             sbar.Items.Add(lbl);
             //<Snippet3>
             ProgressBar progbar = new ProgressBar();
             progbar.Background = Brushes.Gray;
             progbar.Foreground = Brushes.Red;
             progbar.Width = 150;
             progbar.Height = 15;
             progbar.IsIndeterminate = true;
             //</Snippet3>
             sbar.Items.Add(progbar);
        } 
     }
}

   
    
     


ProgressBar with infinite iterations


   
  


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ProgBar.Window1"
    Title ="ProgressBar"
    Width="500">

  <StackPanel>
    <Button Content="One" Click="MakeOne"/>
    <StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" >
      <StatusBarItem>
        <TextBlock>StatusBar</TextBlock>
      </StatusBarItem>
    </StatusBar>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;



namespace ProgBar
{

    public partial class Window1 : Window
    {
        
        private void MakeOne(object sender, RoutedEventArgs e)
        {
           sbar.Items.Clear();
           Label lbl = new Label();
           lbl.Background = new LinearGradientBrush(Colors.LightBlue,        
                                                    Colors.SlateBlue, 90);
           lbl.Content = "ProgressBar with infinite iterations.";
           sbar.Items.Add(lbl);
           ProgressBar progbar = new ProgressBar();
           progbar.Width = 150;
           progbar.Height = 15;
           Duration duration = new Duration(TimeSpan.FromSeconds(1));
           DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
           doubleanimation.RepeatBehavior = RepeatBehavior.Forever;
           progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
           sbar.Items.Add(progbar);
        } 
     }
}

   
    
     


ProgressBar with five iterations


   
  


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ProgBar.Window1"
    Title ="ProgressBar"
    Width="500">

  <StackPanel>
    <Button Content="One" Click="MakeOne"/>
    <StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" >
      <StatusBarItem>
        <TextBlock>StatusBar</TextBlock>
      </StatusBarItem>
    </StatusBar>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;



namespace ProgBar
{

    public partial class Window1 : Window
    {
        
        private void MakeOne(object sender, RoutedEventArgs e)
        {
            sbar.Items.Clear();
            TextBlock txtb = new TextBlock();
            txtb.Text = "ProgressBar with five iterations.";
            sbar.Items.Add(txtb);
            Image image = new Image();
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(@"pack://application:,,,/sunset.png");
            bi.EndInit();
            image.Source = bi;
            ImageBrush imagebrush = new ImageBrush(bi);

            ProgressBar progbar = new ProgressBar();
            progbar.Background = imagebrush;
            progbar.Width = 150;
            progbar.Height = 15;
            Duration duration = new Duration(TimeSpan.FromMilliseconds(2000));
            DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
            doubleanimation.RepeatBehavior = new RepeatBehavior(5);
            progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
            sbar.Items.Add(progbar);
        } 
     }
}

   
    
     


Set grid rectangle template for ProgressBar


   
      
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="120" Width="300">
    <Window.Resources>
        <Style
            TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate 
                        TargetType="{x:Type ProgressBar}">
                        <Grid MinHeight="20" MinWidth="240">
                            <Rectangle Name="PART_Track" Fill="Gainsboro" Stroke="Gray" StrokeThickness="1" />
                            <Rectangle Name="PART_Indicator" Fill="DarkGray" Stroke="Gray" StrokeThickness="1" HorizontalAlignment="Left" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <StackPanel>
        <ProgressBar x:Name="progress" Value="30" HorizontalAlignment="Center" Margin="10"/>
    </StackPanel>

</Window>