feat: simplify dialog option.
This commit is contained in:
@@ -29,7 +29,6 @@ public abstract class DialogControlBase : OverlayFeedbackElement
|
||||
internal double? VerticalOffset { get; set; }
|
||||
internal double? HorizontalOffsetRatio { get; set; }
|
||||
internal double? VerticalOffsetRatio { get; set; }
|
||||
internal bool CanClickOnMaskToClose { get; set; }
|
||||
internal bool CanLightDismiss { get; set; }
|
||||
internal bool CanDragMove { get; set; }
|
||||
|
||||
|
||||
@@ -26,5 +26,4 @@ public class DialogOptions
|
||||
public DialogButton Button { get; set; } = DialogButton.OKCancel;
|
||||
|
||||
public bool IsCloseButtonVisible { get; set; } = true;
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
}
|
||||
@@ -17,16 +17,32 @@ public enum VerticalPosition
|
||||
public class OverlayDialogOptions
|
||||
{
|
||||
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
|
||||
public bool CanClickOnMaskToClose { get; set; } = false;
|
||||
public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.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;
|
||||
/// <summary>
|
||||
/// This attribute is only used when VerticalAnchor is not Center
|
||||
/// </summary>
|
||||
public double? VerticalOffset { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Only works for DefaultDialogControl
|
||||
/// </summary>
|
||||
public DialogMode Mode { get; set; } = DialogMode.None;
|
||||
/// <summary>
|
||||
/// Only works for DefaultDialogControl
|
||||
/// </summary>
|
||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||
/// <summary>
|
||||
/// Only works for DefaultDialogControl
|
||||
/// </summary>
|
||||
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 CanDragMove { get; set; } = true;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class OverlayDialog
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDefaultDialogControl(t, options);
|
||||
host?.AddDialog(t);
|
||||
host.AddDialog(t);
|
||||
}
|
||||
|
||||
public static void Show(Control control, object? vm, string? hostId = null,
|
||||
@@ -32,7 +32,7 @@ public static class OverlayDialog
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDefaultDialogControl(t, options);
|
||||
host?.AddDialog(t);
|
||||
host.AddDialog(t);
|
||||
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ public static class OverlayDialog
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddDialog(t);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddDialog(t);
|
||||
}
|
||||
|
||||
public static void ShowCustom(Control control, object? vm, string? hostId = null,
|
||||
@@ -77,8 +77,8 @@ public static class OverlayDialog
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddDialog(t);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddDialog(t);
|
||||
}
|
||||
|
||||
public static void ShowCustom(object? vm, string? hostId = null,
|
||||
@@ -94,7 +94,7 @@ public static class OverlayDialog
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddDialog(t);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public static class OverlayDialog
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDefaultDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
host.AddModalDialog(t);
|
||||
return t.ShowAsync<DialogResult>(token);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public static class OverlayDialog
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDefaultDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
host.AddModalDialog(t);
|
||||
return t.ShowAsync<DialogResult>(token);
|
||||
}
|
||||
|
||||
@@ -140,8 +140,8 @@ public static class OverlayDialog
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddModalDialog(t);
|
||||
return t.ShowAsync<TResult?>(token);
|
||||
}
|
||||
|
||||
@@ -155,8 +155,8 @@ public static class OverlayDialog
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddModalDialog(t);
|
||||
return t.ShowAsync<TResult?>(token);
|
||||
}
|
||||
|
||||
@@ -173,12 +173,12 @@ public static class OverlayDialog
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
};
|
||||
ConfigureDialogControl(t, options);
|
||||
host?.AddModalDialog(t);
|
||||
ConfigureCustomDialogControl(t, options);
|
||||
host.AddModalDialog(t);
|
||||
return t.ShowAsync<TResult?>(token);
|
||||
}
|
||||
|
||||
private static void ConfigureDialogControl(CustomDialogControl control, OverlayDialogOptions? options)
|
||||
private static void ConfigureCustomDialogControl(CustomDialogControl control, OverlayDialogOptions? options)
|
||||
{
|
||||
options ??= OverlayDialogOptions.Default;
|
||||
control.HorizontalAnchor = options.HorizontalAnchor;
|
||||
@@ -189,8 +189,7 @@ public static class OverlayDialog
|
||||
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
||||
control.VerticalOffset =
|
||||
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
||||
control.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
||||
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
control.IsCloseButtonVisible = options.ShowCloseButton;
|
||||
control.CanLightDismiss = options.CanLightDismiss;
|
||||
control.CanDragMove = options.CanDragMove;
|
||||
}
|
||||
@@ -206,7 +205,6 @@ public static class OverlayDialog
|
||||
control.HorizontalAnchor == HorizontalPosition.Center ? null : options.HorizontalOffset;
|
||||
control.VerticalOffset =
|
||||
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
|
||||
control.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
||||
control.Mode = options.Mode;
|
||||
control.Buttons = options.Buttons;
|
||||
control.Title = options.Title;
|
||||
|
||||
@@ -85,7 +85,7 @@ public partial class OverlayDialogHost
|
||||
PureRectangle? mask = null;
|
||||
if (control.CanLightDismiss)
|
||||
{
|
||||
CreateOverlayMask(false, control.CanLightDismiss);
|
||||
mask = CreateOverlayMask(false, control.CanLightDismiss);
|
||||
}
|
||||
if (mask is not null)
|
||||
{
|
||||
@@ -136,7 +136,7 @@ public partial class OverlayDialogHost
|
||||
/// <param name="control"></param>
|
||||
internal void AddModalDialog(DialogControlBase control)
|
||||
{
|
||||
var mask = CreateOverlayMask(true, control.CanClickOnMaskToClose);
|
||||
var mask = CreateOverlayMask(true, control.CanLightDismiss);
|
||||
_layers.Add(new DialogPair(mask, control));
|
||||
control.SetAsModal(true);
|
||||
ResetZIndices();
|
||||
|
||||
@@ -96,7 +96,7 @@ public partial class OverlayDialogHost: Canvas
|
||||
}
|
||||
else if(canCloseOnClick)
|
||||
{
|
||||
rec.SetCurrentValue(Shape.FillProperty, Brushes.Transparent);
|
||||
rec.SetCurrentValue(PureRectangle.BackgroundProperty, Brushes.Transparent);
|
||||
}
|
||||
if (canCloseOnClick)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user