2 * ToggleButtonAutomationPeer.cs.
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2009 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
14 using System
.Windows
.Automation
;
15 using System
.Windows
.Automation
.Provider
;
16 using System
.Windows
.Controls
;
17 using System
.Windows
.Controls
.Primitives
;
19 namespace System
.Windows
.Automation
.Peers
21 public class ToggleButtonAutomationPeer
: ButtonBaseAutomationPeer
, IToggleProvider
23 public ToggleButtonAutomationPeer (ToggleButton owner
)
28 // UIA Event TogglePatternIdentifiers.ToggleStateProperty
29 // raised by ToggleButton.OnIsCheckedPropertyChanged().
30 toggleState
= ToggleState
;
33 public override object GetPattern (PatternInterface patternInterface
)
35 if (patternInterface
== PatternInterface
.Toggle
)
37 return base.GetPattern (patternInterface
);
40 protected override string GetClassNameCore ()
45 protected override AutomationControlType
GetAutomationControlTypeCore ()
47 return AutomationControlType
.Button
;
50 #region IToggleProvider implementation
52 void IToggleProvider
.Toggle ()
55 throw new ElementNotEnabledException ();
57 bool? isChecked
= owner
.IsChecked
;
58 if (isChecked
== true)
59 owner
.IsChecked
= owner
.IsThreeState
? null : ((bool?) false);
61 owner
.IsChecked
= (bool?) isChecked
.HasValue
;
64 ToggleState IToggleProvider
.ToggleState
{
65 get { return ToggleState; }
70 internal virtual void RaiseToggleStateChanged ()
72 RaisePropertyChangedEvent (TogglePatternIdentifiers
.ToggleStateProperty
,
75 toggleState
= ToggleState
;
78 private ToggleState ToggleState
{
80 bool? isChecked
= owner
.IsChecked
;
81 if (isChecked
.HasValue
)
82 return (isChecked
== true) ? ToggleState
.On
: ToggleState
.Off
;
83 return ToggleState
.Indeterminate
;
87 private ToggleButton owner
;
88 private ToggleState toggleState
;