/// <summary>
/// Custom control used to display a busy indication
/// </summary>
[TemplateVisualState(Name =
"IsBusyState"
, GroupName =
"BusyStatesGroup"
)]
"NormalState"
public
class
BusyIndicator : Control
{
#region Fields
//Data
private
Boolean _isLoaded;
#endregion
#region DPs
/// DP definition for BusyProgressValue property
static
readonly
DependencyProperty BusyMessageProperty = DependencyProperty.Register(
"BusyMessage"
,
typeof
(String),
(BusyIndicator),
new
PropertyMetadata(String.Empty));
DependencyProperty IsBusyProperty = DependencyProperty.Register(
"IsBusy"
(Boolean),
PropertyMetadata(
false
OnIsBusyPropertyChanged));
#region Constructors
/// Initialize a new instance of <see cref="BusyIndicator" />
BusyIndicator()
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}
#region Properties
/// Gets or sets if we are busy or not
Boolean IsBusy
get
return
(Boolean)GetValue(IsBusyProperty);
set
SetValue(IsBusyProperty,
value);
/// Gets or sets the current busy message to display
String BusyMessage
(String)GetValue(BusyMessageProperty);
SetValue(BusyMessageProperty,
#region Handlers
void
OnIsBusyPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
var indicator = d
as
BusyIndicator;
if
((indicator !=
null
) && (indicator._isLoaded))
VisualStateManager.GoToState(indicator,
indicator.IsBusy
?
:
true
);
OnLoaded(
object
sender,
RoutedEventArgs e)
_isLoaded =
;
VisualStateManager.GoToState(
this
IsBusy
OnUnloaded(
<
Application
x:Class
=
"MyProgressIndicatorApp.App"
xmlns
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local
"using:MyProgressIndicatorApp"
RequestedTheme
"Light"
>
Application.Resources
ResourceDictionary
<!--COLORS-->
Color
x:Key
"DarkBlue"
>#3B5998</
<!--BRUSHES-->
SolidColorBrush
"DarkBlueBrush"
"{StaticResource DarkBlue}"
/>
Style
"ProgressIndicatorStyle"
TargetType
"local:BusyIndicator"
Setter
Property
"RequestedTheme"
Value
"Template"
Setter.Value
ControlTemplate
StackPanel
VerticalAlignment
"Center"
HorizontalAlignment
ProgressRing
IsActive
"{TemplateBinding IsBusy}"
Foreground
"{StaticResource DarkBlueBrush}"
Height
"70"
Width
TextBlock
Text
"{TemplateBinding BusyMessage}"
Margin
"0 10 0 0"
</
Grid
Background
"{ThemeResource ApplicationPageBackgroundThemeBrush}"
local:BusyIndicator
"True"
"{StaticResource ProgressIndicatorStyle}"
BusyMessage
"Downloading"
"300"
· Launch the application MyProgressIndicatorApp, we can use the Visual Studio shortcut F5.