1. style
2. cs
public class CustomBusyIndicator : Control
{
private const string PART_CancelButton = "PART_CancelButton";
private Button innerCancelButton;
public event RoutedEventHandler CancelClick;
static CustomBusyIndicator()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomBusyIndicator), new FrameworkPropertyMetadata(typeof(CustomBusyIndicator)));
}
#region BusyContent
public string BusyContent
{
get { return (string)GetValue(BusyContentProperty); }
set { SetValue(BusyContentProperty, value); }
}
public static readonly DependencyProperty BusyCOntentProperty=
DependencyProperty.Register("BusyContent",
typeof(string),
typeof(CustomBusyIndicator),
new PropertyMetadata(""));
#endregion
#region IsBusy
public bool IsBusy
{
get { return (bool)GetValue(IsBusyProperty); }
set { SetValue(IsBusyProperty, value); }
}
public static readonly DependencyProperty IsBusyProperty =
DependencyProperty.Register("IsBusy",
typeof(bool),
typeof(CustomBusyIndicator),
new PropertyMetadata(false));
#endregion
#region Content
public object Content
{
get { return (object)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public static readonly DependencyProperty COntentProperty=
DependencyProperty.Register("Content",
typeof(object),
typeof(CustomBusyIndicator),
new PropertyMetadata(null));
#endregion
#region ContentTemplate
public DataTemplate ContentTemplate
{
get { return (DataTemplate)GetValue(ContentTemplateProperty); }
set { SetValue(ContentTemplateProperty, value); }
}
public static readonly DependencyProperty COntentTemplateProperty=
DependencyProperty.Register("ContentTemplate",
typeof(DataTemplate),
typeof(CustomBusyIndicator),
new PropertyMetadata(null));
#endregion
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (innerCancelButton != null)
{
innerCancelButton.Click -= InnerCancelButton_Click;
}
innerCancelButton = this.GetTemplateChild(PART_CancelButton) as Button;
if (innerCancelButton != null)
{
innerCancelButton.Click += InnerCancelButton_Click;
}
}
private void InnerCancelButton_Click(object sender, RoutedEventArgs e)
{
if (this.IsBusy)
{
this.IsBusy = false;
}
if (this.CancelClick != null)
{
this.CancelClick(this, e);
}
}
}
自定义BusyIndicator控件