4 namespace Tizen.Xamarin.Forms.Extension
7 /// The dialog widget displays its content with buttons and title.
11 /// var dialog = new Dialog();
12 /// dialog.Title = "Dialog"
14 /// var positive = new Button()
18 /// var negative = new Button()
22 /// negative.Clicked += (s,e)=>
27 /// dialog.Positive = positive;
28 /// dialog.Negative = negative;
30 /// var label = new Label()
32 /// Text = "New Dialog"
35 /// dialog.Content = label;
41 public class Dialog : BindableObject
44 /// BindableProperty. Identifies the content bindable property.
46 public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(Dialog), null);
49 /// BindableProperty. Identifies the positive bindable property.
51 public static readonly BindableProperty PositiveProperty = BindableProperty.Create(nameof(Positive), typeof(Button), typeof(Dialog), null);
54 /// BindableProperty. Identifies the neutral bindable property.
56 public static readonly BindableProperty NeutralProperty = BindableProperty.Create(nameof(Neutral), typeof(Button), typeof(Dialog), null);
59 /// BindableProperty. Identifies the negative bindable property.
61 public static readonly BindableProperty NegativeProperty = BindableProperty.Create(nameof(Negative), typeof(Button), typeof(Dialog), null);
64 /// BindableProperty. Identifies the title bindable property.
66 public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(Dialog), null);
69 /// BindableProperty. Identifies the subtitle bindable property.
71 public static readonly BindableProperty SubtitleProperty = BindableProperty.Create(nameof(Subtitle), typeof(string), typeof(Dialog), null);
74 /// BindableProperty. Identifies the HorizontalOption bindable property.
76 public static readonly BindableProperty HorizontalOptionProperty = BindableProperty.Create(nameof(HorizontalOption), typeof(LayoutOptions), typeof(Dialog), LayoutOptions.Center);
79 /// BindableProperty. Identifies the VerticalOption bindable property.
81 public static readonly BindableProperty VerticalOptionProperty = BindableProperty.Create(nameof(VerticalOption), typeof(LayoutOptions), typeof(Dialog), LayoutOptions.End);
83 IDialog _dialog = null;
86 /// Occurs when the dialog is hidden.
88 public event EventHandler Hidden;
91 /// Occurs when outside of the dialog is clicked.
93 public event EventHandler OutsideClicked;
96 /// Occurs when the dialog is shown on the display.
98 public event EventHandler Shown;
101 /// Occurs when the device's back button is pressed.
103 public event EventHandler BackButtonPressed;
107 _dialog = DependencyService.Get<IDialog>(DependencyFetchTarget.NewInstance);
110 throw new Exception("Object reference not set to an instance of a Dialog.");
113 _dialog.Hidden += (s, e) =>
115 Hidden?.Invoke(this, EventArgs.Empty);
118 _dialog.OutsideClicked += (s, e) =>
120 OutsideClicked?.Invoke(this, EventArgs.Empty);
123 _dialog.Shown += (s, e) =>
125 Shown?.Invoke(this, EventArgs.Empty);
128 _dialog.BackButtonPressed += (s, e) =>
130 BackButtonPressed?.Invoke(this, EventArgs.Empty);
133 SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _dialog));
134 SetBinding(PositiveProperty, new Binding(nameof(Positive), mode: BindingMode.OneWayToSource, source: _dialog));
135 SetBinding(NeutralProperty, new Binding(nameof(Neutral), mode: BindingMode.OneWayToSource, source: _dialog));
136 SetBinding(NegativeProperty, new Binding(nameof(Negative), mode: BindingMode.OneWayToSource, source: _dialog));
137 SetBinding(TitleProperty, new Binding(nameof(Title), mode: BindingMode.OneWayToSource, source: _dialog));
138 SetBinding(SubtitleProperty, new Binding(nameof(Subtitle), mode: BindingMode.OneWayToSource, source: _dialog));
139 SetBinding(HorizontalOptionProperty, new Binding(nameof(HorizontalOption), mode: BindingMode.OneWayToSource, source: _dialog));
140 SetBinding(VerticalOptionProperty, new Binding(nameof(VerticalOption), mode: BindingMode.OneWayToSource, source: _dialog));
144 /// Gets or sets content view of the dialog.
148 get { return (View)GetValue(ContentProperty); }
149 set { SetValue(ContentProperty, value); }
153 /// Gets or sets positive button of the dialog.
154 /// This button is on the left.
155 /// When used alone, it is variable in size (can increase to the size of dialog).
156 /// Dialog's all buttons style is bottom
158 public Button Positive
160 get { return (Button)GetValue(PositiveProperty); }
161 set { SetValue(PositiveProperty, value); }
165 /// Gets or sets neutral button of the dialog.
166 /// This button is at the center.
167 /// When used alone or used with positive, its size is half the size of the dialog and is on the right.
169 public Button Neutral
171 get { return (Button)GetValue(NeutralProperty); }
172 set { SetValue(NeutralProperty, value); }
176 /// Gets or sets negative button of the dialog.
177 /// This button is always on the right and is displayed at a fixed size.
179 public Button Negative
181 get { return (Button)GetValue(NegativeProperty); }
182 set { SetValue(NegativeProperty, value); }
186 /// Gets or sets title of the dialog.
190 get { return (string)GetValue(TitleProperty); }
191 set { SetValue(TitleProperty, value); }
195 /// Gets or sets subtitle of the dialog.
196 /// When title property value is null, subtitle is not displayed.
198 public string Subtitle
200 get { return (string)GetValue(SubtitleProperty); }
201 set { SetValue(SubtitleProperty, value); }
205 /// Gets or sets the LayoutOptions that define how the dialog gets laid in a layout cycle.
206 /// The default is center.
208 public LayoutOptions HorizontalOption
210 get { return (LayoutOptions)GetValue(HorizontalOptionProperty); }
211 set { SetValue(HorizontalOptionProperty, value); }
215 /// Gets or sets the LayoutOptions that define how the dialog gets laid in a layout cycle.
216 /// The default is end.
218 public LayoutOptions VerticalOption
220 get { return (LayoutOptions)GetValue(VerticalOptionProperty); }
221 set { SetValue(VerticalOptionProperty, value); }
225 /// Shows the dialog.
233 /// Hides the dialog.