5
// Eric Maupin <ermau@xamarin.com>
7
// Copyright (c) 2012 Xamarin, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Windows.Controls;
32
using WindowsCheckBox = System.Windows.Controls.CheckBox;
34
namespace Xwt.WPFBackend
36
public class CheckBoxBackend
37
: WidgetBackend, ICheckBoxBackend
39
public CheckBoxBackend()
41
Widget = new WindowsCheckBox ();
44
public void SetContent (IWidgetBackend widget)
47
throw new ArgumentNullException ("widget");
49
CheckBox.Content = widget.NativeWidget;
52
public void SetContent (string label)
54
CheckBox.Content = new TextBlock { Text = label };
59
get { return CheckBox.IsChecked.HasValue && CheckBox.IsChecked.Value; }
60
set { CheckBox.IsChecked = value; }
65
get { return !CheckBox.IsChecked.HasValue; }
69
CheckBox.IsChecked = null;
71
CheckBox.IsChecked = false;
75
public bool AllowMixed
77
get { return CheckBox.IsThreeState; }
78
set { CheckBox.IsThreeState = value; }
81
public override void EnableEvent (object eventId)
83
base.EnableEvent (eventId);
84
if (eventId is CheckBoxEvent) {
85
switch ((CheckBoxEvent)eventId) {
86
case CheckBoxEvent.Clicked:
87
CheckBox.Click += OnClicked;
90
case CheckBoxEvent.Toggled:
91
CheckBox.Checked += OnChecked;
97
public override void DisableEvent (object eventId)
99
base.DisableEvent (eventId);
100
if (eventId is CheckBoxEvent) {
101
switch ((CheckBoxEvent)eventId) {
102
case CheckBoxEvent.Clicked:
103
CheckBox.Click -= OnClicked;
106
case CheckBoxEvent.Toggled:
107
CheckBox.Checked -= OnChecked;
113
private void OnChecked (object sender, RoutedEventArgs routedEventArgs)
115
Toolkit.Invoke (CheckBoxEventSink.OnToggled);
118
private void OnClicked (object sender, RoutedEventArgs e)
120
Toolkit.Invoke (CheckBoxEventSink.OnClicked);
123
protected ICheckBoxEventSink CheckBoxEventSink
125
get { return (ICheckBoxEventSink) EventSink; }
128
protected WindowsCheckBox CheckBox
130
get { return (WindowsCheckBox) Widget; }