using System; using Xamarin.Forms; namespace Tizen.Xamarin.Forms.Extension { /// /// The dialog widget displays its content with buttons and title. /// /// /// /// var dialog = new Dialog(); /// dialog.Title = "Dialog" /// /// var positive = new Button() /// { /// Text = "OK" /// } /// var negative = new Button() /// { /// Text = "Cancel" /// } /// negative.Clicked += (s,e)=> /// { /// dialog.Hide(); /// } /// /// dialog.Positive = positive; /// dialog.Negative = negative; /// /// var label = new Label() /// { /// Text = "New Dialog" /// } /// /// dialog.Content = label; /// /// dialog.Show(); /// /// /// public class Dialog : BindableObject { /// /// BindableProperty. Identifies the content bindable property. /// public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(Dialog), null); /// /// BindableProperty. Identifies the positive bindable property. /// public static readonly BindableProperty PositiveProperty = BindableProperty.Create(nameof(Positive), typeof(Button), typeof(Dialog), null); /// /// BindableProperty. Identifies the neutral bindable property. /// public static readonly BindableProperty NeutralProperty = BindableProperty.Create(nameof(Neutral), typeof(Button), typeof(Dialog), null); /// /// BindableProperty. Identifies the negative bindable property. /// public static readonly BindableProperty NegativeProperty = BindableProperty.Create(nameof(Negative), typeof(Button), typeof(Dialog), null); /// /// BindableProperty. Identifies the title bindable property. /// public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(Dialog), null); /// /// BindableProperty. Identifies the subtitle bindable property. /// public static readonly BindableProperty SubtitleProperty = BindableProperty.Create(nameof(Subtitle), typeof(string), typeof(Dialog), null); /// /// BindableProperty. Identifies the HorizontalOption bindable property. /// public static readonly BindableProperty HorizontalOptionProperty = BindableProperty.Create(nameof(HorizontalOption), typeof(LayoutOptions), typeof(Dialog), LayoutOptions.Center); /// /// BindableProperty. Identifies the VerticalOption bindable property. /// public static readonly BindableProperty VerticalOptionProperty = BindableProperty.Create(nameof(VerticalOption), typeof(LayoutOptions), typeof(Dialog), LayoutOptions.End); IDialog _dialog = null; /// /// Occurs when the dialog is hidden. /// public event EventHandler Hidden; /// /// Occurs when outside of the dialog is clicked. /// public event EventHandler OutsideClicked; /// /// Occurs when the dialog is shown on the display. /// public event EventHandler Shown; /// /// Occurs when the device's back button is pressed. /// public event EventHandler BackButtonPressed; public Dialog() { _dialog = DependencyService.Get(DependencyFetchTarget.NewInstance); if (_dialog == null) { throw new Exception("Object reference not set to an instance of a Dialog."); } _dialog.Hidden += (s, e) => { Hidden?.Invoke(this, EventArgs.Empty); }; _dialog.OutsideClicked += (s, e) => { OutsideClicked?.Invoke(this, EventArgs.Empty); }; _dialog.Shown += (s, e) => { Shown?.Invoke(this, EventArgs.Empty); }; _dialog.BackButtonPressed += (s, e) => { BackButtonPressed?.Invoke(this, EventArgs.Empty); }; SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(PositiveProperty, new Binding(nameof(Positive), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(NeutralProperty, new Binding(nameof(Neutral), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(NegativeProperty, new Binding(nameof(Negative), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(TitleProperty, new Binding(nameof(Title), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(SubtitleProperty, new Binding(nameof(Subtitle), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(HorizontalOptionProperty, new Binding(nameof(HorizontalOption), mode: BindingMode.OneWayToSource, source: _dialog)); SetBinding(VerticalOptionProperty, new Binding(nameof(VerticalOption), mode: BindingMode.OneWayToSource, source: _dialog)); } /// /// Gets or sets content view of the dialog. /// public View Content { get { return (View)GetValue(ContentProperty); } set { SetValue(ContentProperty, value); } } /// /// Gets or sets positive button of the dialog. /// This button is on the left. /// When used alone, it is variable in size (can increase to the size of dialog). /// Dialog's all buttons style is bottom /// public Button Positive { get { return (Button)GetValue(PositiveProperty); } set { SetValue(PositiveProperty, value); } } /// /// Gets or sets neutral button of the dialog. /// This button is at the center. /// When used alone or used with positive, its size is half the size of the dialog and is on the right. /// public Button Neutral { get { return (Button)GetValue(NeutralProperty); } set { SetValue(NeutralProperty, value); } } /// /// Gets or sets negative button of the dialog. /// This button is always on the right and is displayed at a fixed size. /// public Button Negative { get { return (Button)GetValue(NegativeProperty); } set { SetValue(NegativeProperty, value); } } /// /// Gets or sets title of the dialog. /// public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } /// /// Gets or sets subtitle of the dialog. /// When title property value is null, subtitle is not displayed. /// public string Subtitle { get { return (string)GetValue(SubtitleProperty); } set { SetValue(SubtitleProperty, value); } } /// /// Gets or sets the LayoutOptions that define how the dialog gets laid in a layout cycle. /// The default is center. /// public LayoutOptions HorizontalOption { get { return (LayoutOptions)GetValue(HorizontalOptionProperty); } set { SetValue(HorizontalOptionProperty, value); } } /// /// Gets or sets the LayoutOptions that define how the dialog gets laid in a layout cycle. /// The default is end. /// public LayoutOptions VerticalOption { get { return (LayoutOptions)GetValue(VerticalOptionProperty); } set { SetValue(VerticalOptionProperty, value); } } /// /// Shows the dialog. /// public void Show() { _dialog.Show(); } /// /// Hides the dialog. /// public void Hide() { _dialog.Hide(); } } }