5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 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
33
public class Button: Widget
36
ButtonStyle style = ButtonStyle.Normal;
37
ButtonType type = ButtonType.Normal;
40
ContentPosition imagePosition = ContentPosition.Left;
42
protected new class WidgetBackendHost: Widget.WidgetBackendHost, IButtonEventSink
44
protected override void OnBackendCreated ()
46
base.OnBackendCreated ();
47
((IButtonBackend)Backend).SetButtonStyle (((Button)Parent).style);
50
public void OnClicked ()
52
((Button)Parent).OnClicked (EventArgs.Empty);
58
MapEvent (ButtonEvent.Clicked, typeof(Button), "OnClicked");
65
public Button (string label): this ()
70
public Button (Image img, string label): this ()
76
public Button (Image img): this ()
81
protected override BackendHost CreateBackendHost ()
83
return new WidgetBackendHost ();
86
IButtonBackend Backend {
87
get { return (IButtonBackend) BackendHost.Backend; }
94
Backend.SetContent (label, XwtObject.GetBackend (image), imagePosition);
95
OnPreferredSizeChanged ();
100
get { return image; }
103
Backend.SetContent (label, XwtObject.GetBackend (value), imagePosition);
104
OnPreferredSizeChanged ();
108
public ContentPosition ImagePosition {
109
get { return imagePosition; }
111
imagePosition = value;
112
Backend.SetContent (label, XwtObject.GetBackend (image), imagePosition);
113
OnPreferredSizeChanged ();
117
public ButtonStyle Style {
118
get { return style; }
121
Backend.SetButtonStyle (style);
122
OnPreferredSizeChanged ();
126
public ButtonType Type {
130
Backend.SetButtonType (type);
131
OnPreferredSizeChanged ();
135
protected virtual void OnClicked (EventArgs e)
141
public event EventHandler Clicked {
143
BackendHost.OnBeforeEventAdd (ButtonEvent.Clicked, clicked);
148
BackendHost.OnAfterEventRemove (ButtonEvent.Clicked, clicked);