Create a Begin,Pause,Resume,Stop button using WPF

Pardhu2020
Posted by in WPF category on for Beginner level | Points: 250 | Views : 4043 red flag

In this article, we will discuss how to create a Begin,Pause,Resume,Stop button using WPF

Introduction

Hi friends today we will discuss  how to create a Begin,Pause,Resume,Stop button using WPF.


  1. Once open the Visual Studio click on File Click on the Project .

  1. As you are seeing there are many application from them Select WPF application .
  2. At name rename it as per your requirement .

  1. Right click on the project and click on add from there click on window for adding a new window to the project.
  2. Rename the window as per your requirement.

  1. Its time to design your window screen …
  2. Drag and drop a Rectangle into your screen and color it Blue ..
  3. Drag and drop five Buttons and rename it as showed above .
  4. Now it time to make button functionality using the code below.

<Window x:Class="StoryBoardApp1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel Margin="10"> <Rectangle Name="MyRectangle" Width="100" Height="100" Fill="Blue"> </Rectangle> <Button Name="BeginButton">Begin</Button> <Button Name="PauseButton">Pause</Button> <Button Name="ResumeButton">Resume</Button> <Button Name="SkipToFillButton">Skip To Fill</Button> <Button Name="StopButton">Stop</Button> <StackPanel.Triggers> <EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton"> <BeginStoryboard Name="MyBeginStoryboard"> <Storyboard> <DoubleAnimation Storyboard.TargetName="MyRectangle" Storyboard.TargetProperty="(Rectangle.Opacity)" From="1.0" To="0.0" Duration="0:0:5" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Button.Click" SourceName="PauseButton"> <PauseStoryboard BeginStoryboardName="MyBeginStoryboard" /> </EventTrigger> <EventTrigger RoutedEvent="Button.Click" SourceName="ResumeButton"> <ResumeStoryboard BeginStoryboardName="MyBeginStoryboard" /> </EventTrigger> <EventTrigger RoutedEvent="Button.Click" SourceName="SkipToFillButton"> <SkipStoryboardToFill BeginStoryboardName="MyBeginStoryboard" /> </EventTrigger> <EventTrigger RoutedEvent="Button.Click" SourceName="StopButton"> <StopStoryboard BeginStoryboardName="MyBeginStoryboard" /> </EventTrigger> </StackPanel.Triggers> </StackPanel> </Window>


Code in Window1.xaml.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;

namespace StoryBoardApp1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    }
}


Out Put :





Conclusion:


In this article we have seen how to create a Begin,Pause,Resume,Stop button using WPF.








Page copy protected against web site content infringement by Copyscape

About the Author

Pardhu2020
Full Name: Pardha Saradhi
Member Level:
Member Status: Member
Member Since: 3/19/2013 2:21:22 PM
Country: India

http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)