Skip to content

Instantly share code, notes, and snippets.

@julesx
Created July 31, 2014 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/24719d92b9dec8a58768 to your computer and use it in GitHub Desktop.
Save julesx/24719d92b9dec8a58768 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
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.Navigation;
using System.Windows.Shapes;
using WpfApplication30.Annotations;
namespace WpfApplication30
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : INotifyPropertyChanged
{
private bool _doingWork;
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public bool DoingWork
{
get { return _doingWork; }
set
{
_doingWork = value;
OnPropertyChanged("DoingWork");
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
DoingWork = true;
Task.Factory.StartNew(delegate
{
//Look at me doing some work, going to take about 15 seconds
Thread.Sleep(15000);
DoingWork = false;
});
}
}
}
<Window x:Class="WpfApplication30.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication30="clr-namespace:WpfApplication30"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Grid.Resources>
<wpfApplication30:CircularProgressBar Height="30" Width="30" Visibility="{Binding DoingWork, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Button VerticalAlignment="Bottom" Click="ButtonBase_OnClick" Content="Do Work" Height="35" Width="100" Margin="0,0,0,25"></Button>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment