comparison SilverlightGlimpse/SilverFlow.Controls/FloatingWindow/BootstrapButton.cs @ 63:536498832a79

Latest version before changing bindings to Listbox
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sun, 22 Apr 2012 13:33:42 +0100
parents
children
comparison
equal deleted inserted replaced
62:810116cd6b8e 63:536498832a79
1 using System.Windows;
2 using System.Windows.Controls;
3
4 namespace SilverFlow.Controls
5 {
6 /// <summary>
7 /// Two-state button with an up/down arrow.
8 /// </summary>
9 [TemplateVisualState(Name = VSMSTATE_StateClose, GroupName = VSMGROUP_ButtonStates)]
10 [TemplateVisualState(Name = VSMSTATE_StateOpen, GroupName = VSMGROUP_ButtonStates)]
11 public class BootstrapButton : Button
12 {
13 // VSM groups
14 private const string VSMGROUP_ButtonStates = "ButtonStates";
15
16 // VSM states
17 private const string VSMSTATE_StateOpen = "Open";
18 private const string VSMSTATE_StateClose = "Close";
19
20 #region public bool IsOpen
21
22 /// <summary>
23 /// Gets or sets a value indicating whether the bootstrap button is in the "Open" state.
24 /// </summary>
25 /// <value><c>true</c> if the bootstrap button is in the "Open" state; otherwise, <c>false</c>.</value>
26 public bool IsOpen
27 {
28 get { return (bool)GetValue(IsOpenProperty); }
29 set { SetValue(IsOpenProperty, value); }
30 }
31
32 /// <summary>
33 /// Identifies the <see cref="BootstrapButton.IsOpen" /> dependency property.
34 /// </summary>
35 /// <value>
36 /// The identifier for the <see cref="BootstrapButton.IsOpen" /> dependency property.
37 /// </value>
38 public static readonly DependencyProperty IsOpenProperty =
39 DependencyProperty.Register(
40 "IsOpen",
41 typeof(bool),
42 typeof(BootstrapButton),
43 new PropertyMetadata(false, IsOpenPropertyChanged));
44
45 /// <summary>
46 /// IsOpenProperty PropertyChangedCallback call back static function.
47 /// </summary>
48 /// <param name="d">BootstrapButton object whose IsOpenProperty property is changed.</param>
49 /// <param name="e">DependencyPropertyChangedEventArgs which contains the old and new values.</param>
50 private static void IsOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
51 {
52 BootstrapButton button = (BootstrapButton)d;
53 VisualStateManager.GoToState(
54 button,
55 (bool)e.NewValue ? VSMSTATE_StateClose : VSMSTATE_StateOpen,
56 true);
57 }
58
59 #endregion
60
61 /// <summary>
62 /// Raises the <see cref="E:System.Windows.Controls.Primitives.ButtonBase.Click"/> event.
63 /// </summary>
64 protected override void OnClick()
65 {
66 // Toggle open/closed state
67 IsOpen = !IsOpen;
68
69 base.OnClick();
70 }
71 }
72 }