feat: simplify dialog option.
This commit is contained in:
@@ -36,8 +36,7 @@
|
|||||||
OnContent="Modal" />
|
OnContent="Modal" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ClickOnMaskToClose"
|
Content="ClickOnMaskToClose"
|
||||||
IsChecked="{Binding CanCloseMaskToClose}"
|
IsChecked="{Binding CanLightDismiss}"
|
||||||
IsVisible="{Binding #defaultModal.IsChecked}"
|
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
@@ -81,8 +80,7 @@
|
|||||||
OnContent="Modal" />
|
OnContent="Modal" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ClickOnMaskToClose"
|
Content="ClickOnMaskToClose"
|
||||||
IsChecked="{Binding CanCloseMaskToClose}"
|
IsChecked="{Binding CanLightDismiss}"
|
||||||
IsVisible="{Binding #modal.IsChecked}"
|
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Dialog" />
|
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Dialog" />
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
set => SetProperty(ref _isModal, value);
|
set => SetProperty(ref _isModal, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _canCloseMaskToClose;
|
private bool _canLightDismiss;
|
||||||
public bool CanCloseMaskToClose
|
public bool CanLightDismiss
|
||||||
{
|
{
|
||||||
get => _canCloseMaskToClose;
|
get => _canLightDismiss;
|
||||||
set => SetProperty(ref _canCloseMaskToClose, value);
|
set => SetProperty(ref _canLightDismiss, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DialogResult? _defaultResult;
|
private DialogResult? _defaultResult;
|
||||||
@@ -118,7 +118,7 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
Title = "Please select a date",
|
Title = "Please select a date",
|
||||||
Mode = SelectedMode,
|
Mode = SelectedMode,
|
||||||
Buttons = SelectedButton,
|
Buttons = SelectedButton,
|
||||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
CanLightDismiss = CanLightDismiss,
|
||||||
HorizontalAnchor = HorizontalPosition.Right,
|
HorizontalAnchor = HorizontalPosition.Right,
|
||||||
HorizontalOffset = 50,
|
HorizontalOffset = 50,
|
||||||
VerticalAnchor = VerticalPosition.Top,
|
VerticalAnchor = VerticalPosition.Top,
|
||||||
@@ -136,7 +136,8 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
{
|
{
|
||||||
Title = "Please select a date",
|
Title = "Please select a date",
|
||||||
Mode = SelectedMode,
|
Mode = SelectedMode,
|
||||||
Buttons = SelectedButton
|
Buttons = SelectedButton,
|
||||||
|
CanLightDismiss = CanLightDismiss,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,14 +170,15 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
Result = await OverlayDialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
|
Result = await OverlayDialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
|
||||||
vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions()
|
vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions()
|
||||||
{
|
{
|
||||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
CanLightDismiss = CanLightDismiss,
|
||||||
});
|
});
|
||||||
Date = vm.Date;
|
Date = vm.Date;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
|
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
|
||||||
IsGlobal ? null : "LocalHost");
|
IsGlobal ? null : "LocalHost",
|
||||||
|
options: new OverlayDialogOptions{ CanLightDismiss = CanLightDismiss });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
|||||||
internal double? VerticalOffset { get; set; }
|
internal double? VerticalOffset { get; set; }
|
||||||
internal double? HorizontalOffsetRatio { get; set; }
|
internal double? HorizontalOffsetRatio { get; set; }
|
||||||
internal double? VerticalOffsetRatio { get; set; }
|
internal double? VerticalOffsetRatio { get; set; }
|
||||||
internal bool CanClickOnMaskToClose { get; set; }
|
|
||||||
internal bool CanLightDismiss { get; set; }
|
internal bool CanLightDismiss { get; set; }
|
||||||
internal bool CanDragMove { get; set; }
|
internal bool CanDragMove { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -26,5 +26,4 @@ public class DialogOptions
|
|||||||
public DialogButton Button { get; set; } = DialogButton.OKCancel;
|
public DialogButton Button { get; set; } = DialogButton.OKCancel;
|
||||||
|
|
||||||
public bool IsCloseButtonVisible { get; set; } = true;
|
public bool IsCloseButtonVisible { get; set; } = true;
|
||||||
public bool CanDragMove { get; set; } = true;
|
|
||||||
}
|
}
|
||||||
@@ -17,16 +17,32 @@ public enum VerticalPosition
|
|||||||
public class OverlayDialogOptions
|
public class OverlayDialogOptions
|
||||||
{
|
{
|
||||||
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
|
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
|
||||||
public bool CanClickOnMaskToClose { get; set; } = false;
|
|
||||||
public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
|
public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
|
||||||
public VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
|
public VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
|
||||||
|
/// <summary>
|
||||||
|
/// This attribute is only used when HorizontalAnchor is not Center
|
||||||
|
/// </summary>
|
||||||
public double? HorizontalOffset { get; set; } = null;
|
public double? HorizontalOffset { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// This attribute is only used when VerticalAnchor is not Center
|
||||||
|
/// </summary>
|
||||||
public double? VerticalOffset { get; set; } = null;
|
public double? VerticalOffset { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Only works for DefaultDialogControl
|
||||||
|
/// </summary>
|
||||||
public DialogMode Mode { get; set; } = DialogMode.None;
|
public DialogMode Mode { get; set; } = DialogMode.None;
|
||||||
|
/// <summary>
|
||||||
|
/// Only works for DefaultDialogControl
|
||||||
|
/// </summary>
|
||||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||||
|
/// <summary>
|
||||||
|
/// Only works for DefaultDialogControl
|
||||||
|
/// </summary>
|
||||||
public string? Title { get; set; } = null;
|
public string? Title { get; set; } = null;
|
||||||
public bool IsCloseButtonVisible { get; set; } = true;
|
/// <summary>
|
||||||
|
/// Only works for CustomDialogControl
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowCloseButton { get; set; } = true;
|
||||||
public bool CanLightDismiss { get; set; }
|
public bool CanLightDismiss { get; set; }
|
||||||
public bool CanDragMove { get; set; } = true;
|
public bool CanDragMove { get; set; } = true;
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ public static class OverlayDialog
|
|||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDefaultDialogControl(t, options);
|
ConfigureDefaultDialogControl(t, options);
|
||||||
host?.AddDialog(t);
|
host.AddDialog(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Show(Control control, object? vm, string? hostId = null,
|
public static void Show(Control control, object? vm, string? hostId = null,
|
||||||
@@ -32,7 +32,7 @@ public static class OverlayDialog
|
|||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDefaultDialogControl(t, options);
|
ConfigureDefaultDialogControl(t, options);
|
||||||
host?.AddDialog(t);
|
host.AddDialog(t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +63,8 @@ public static class OverlayDialog
|
|||||||
Content = new TView(),
|
Content = new TView(),
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host?.AddDialog(t);
|
host.AddDialog(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowCustom(Control control, object? vm, string? hostId = null,
|
public static void ShowCustom(Control control, object? vm, string? hostId = null,
|
||||||
@@ -77,8 +77,8 @@ public static class OverlayDialog
|
|||||||
Content = control,
|
Content = control,
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host?.AddDialog(t);
|
host.AddDialog(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowCustom(object? vm, string? hostId = null,
|
public static void ShowCustom(object? vm, string? hostId = null,
|
||||||
@@ -94,7 +94,7 @@ public static class OverlayDialog
|
|||||||
Content = view,
|
Content = view,
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host.AddDialog(t);
|
host.AddDialog(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public static class OverlayDialog
|
|||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDefaultDialogControl(t, options);
|
ConfigureDefaultDialogControl(t, options);
|
||||||
host?.AddModalDialog(t);
|
host.AddModalDialog(t);
|
||||||
return t.ShowAsync<DialogResult>(token);
|
return t.ShowAsync<DialogResult>(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ public static class OverlayDialog
|
|||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDefaultDialogControl(t, options);
|
ConfigureDefaultDialogControl(t, options);
|
||||||
host?.AddModalDialog(t);
|
host.AddModalDialog(t);
|
||||||
return t.ShowAsync<DialogResult>(token);
|
return t.ShowAsync<DialogResult>(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ public static class OverlayDialog
|
|||||||
Content = new TView(),
|
Content = new TView(),
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host?.AddModalDialog(t);
|
host.AddModalDialog(t);
|
||||||
return t.ShowAsync<TResult?>(token);
|
return t.ShowAsync<TResult?>(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,8 +155,8 @@ public static class OverlayDialog
|
|||||||
Content = control,
|
Content = control,
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host?.AddModalDialog(t);
|
host.AddModalDialog(t);
|
||||||
return t.ShowAsync<TResult?>(token);
|
return t.ShowAsync<TResult?>(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,12 +173,12 @@ public static class OverlayDialog
|
|||||||
Content = view,
|
Content = view,
|
||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDialogControl(t, options);
|
ConfigureCustomDialogControl(t, options);
|
||||||
host?.AddModalDialog(t);
|
host.AddModalDialog(t);
|
||||||
return t.ShowAsync<TResult?>(token);
|
return t.ShowAsync<TResult?>(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConfigureDialogControl(CustomDialogControl control, OverlayDialogOptions? options)
|
private static void ConfigureCustomDialogControl(CustomDialogControl control, OverlayDialogOptions? options)
|
||||||
{
|
{
|
||||||
options ??= OverlayDialogOptions.Default;
|
options ??= OverlayDialogOptions.Default;
|
||||||
control.HorizontalAnchor = options.HorizontalAnchor;
|
control.HorizontalAnchor = options.HorizontalAnchor;
|
||||||
@@ -189,8 +189,7 @@ public static class OverlayDialog
|
|||||||
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
||||||
control.VerticalOffset =
|
control.VerticalOffset =
|
||||||
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
||||||
control.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
control.IsCloseButtonVisible = options.ShowCloseButton;
|
||||||
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
|
||||||
control.CanLightDismiss = options.CanLightDismiss;
|
control.CanLightDismiss = options.CanLightDismiss;
|
||||||
control.CanDragMove = options.CanDragMove;
|
control.CanDragMove = options.CanDragMove;
|
||||||
}
|
}
|
||||||
@@ -206,7 +205,6 @@ public static class OverlayDialog
|
|||||||
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
||||||
control.VerticalOffset =
|
control.VerticalOffset =
|
||||||
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
||||||
control.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
|
||||||
control.Mode = options.Mode;
|
control.Mode = options.Mode;
|
||||||
control.Buttons = options.Buttons;
|
control.Buttons = options.Buttons;
|
||||||
control.Title = options.Title;
|
control.Title = options.Title;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public partial class OverlayDialogHost
|
|||||||
PureRectangle? mask = null;
|
PureRectangle? mask = null;
|
||||||
if (control.CanLightDismiss)
|
if (control.CanLightDismiss)
|
||||||
{
|
{
|
||||||
CreateOverlayMask(false, control.CanLightDismiss);
|
mask = CreateOverlayMask(false, control.CanLightDismiss);
|
||||||
}
|
}
|
||||||
if (mask is not null)
|
if (mask is not null)
|
||||||
{
|
{
|
||||||
@@ -136,7 +136,7 @@ public partial class OverlayDialogHost
|
|||||||
/// <param name="control"></param>
|
/// <param name="control"></param>
|
||||||
internal void AddModalDialog(DialogControlBase control)
|
internal void AddModalDialog(DialogControlBase control)
|
||||||
{
|
{
|
||||||
var mask = CreateOverlayMask(true, control.CanClickOnMaskToClose);
|
var mask = CreateOverlayMask(true, control.CanLightDismiss);
|
||||||
_layers.Add(new DialogPair(mask, control));
|
_layers.Add(new DialogPair(mask, control));
|
||||||
control.SetAsModal(true);
|
control.SetAsModal(true);
|
||||||
ResetZIndices();
|
ResetZIndices();
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public partial class OverlayDialogHost: Canvas
|
|||||||
}
|
}
|
||||||
else if(canCloseOnClick)
|
else if(canCloseOnClick)
|
||||||
{
|
{
|
||||||
rec.SetCurrentValue(Shape.FillProperty, Brushes.Transparent);
|
rec.SetCurrentValue(PureRectangle.BackgroundProperty, Brushes.Transparent);
|
||||||
}
|
}
|
||||||
if (canCloseOnClick)
|
if (canCloseOnClick)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user