I’m trying to create my own ChildWindow whith BusyIndicator. This ChildWindow will be a base class for my other child windows. I started from creating a class which inherits from ChildWindow and I added some additional DependencyProperties.
public class ChildWindowBase : ChildWindow
{
public bool IsBusy
{
get { return (bool)GetValue(IsBusyProperty); }
set { SetValue(IsBusyProperty, value); }
}
public static readonly DependencyProperty IsBusyProperty =
DependencyProperty.Register("IsBusy", typeof(bool), typeof(ChildWindowBase), new PropertyMetadata(false));
public string BusyContent
{
get { return (string)GetValue(BusyContentProperty); }
set { SetValue(BusyContentProperty, value); }
}
// Using a DependencyProperty as the backing store for BusyContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BusyContentProperty =
DependencyProperty.Register("BusyContent", typeof(string), typeof(ChildWindowBase), new PropertyMetadata("Busy..."));
}
In the next step I created a style which modifies template of ChildWindow
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:Controls="clr-namespace:Sockets.Shared.Controls;assembly=Sockets.Shared">
<Style TargetType="Controls:ChildWindowBase">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<toolkit:BusyIndicator HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BusyContent="{TemplateBinding BusyContent}" IsBusy="{TemplateBinding IsBusy}" >
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
</toolkit:BusyIndicator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Now if I want to create another ChildWindow I do sth like that
<Controls:ChildWindowBase x:Class="Client.Silverlight.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginView" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:Controls="clr-namespace:Sockets.Shared.Controls;assembly=Sockets.Shared" Width="400" Height="300" IsBusy="True">
//some code in here
</Controls:ChildWindowBase>
The problem is that my ChildWindows do not have an application bar (bar with close button and window title). Is there any way to modify my template to show it, or maybe I have to write my custom application bar? If so what is the best way to do that ?
A ChildWindow has a ContentTemplate property. Set your BusyWindow template in the ContentTemplate rather than the Template property and it should work.