feat: Add CanDragMove option to dialogs and make sure it can be disabled.
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
u:FormItem.Label="Is Close Button Visible"
|
||||
IsChecked="{Binding IsCloseButtonVisible}"
|
||||
IsThreeState="True" />
|
||||
<CheckBox u:FormItem.Label="CanDragMove" IsChecked="{Binding CanDragMove}" />
|
||||
<Button
|
||||
HorizontalAlignment="Left"
|
||||
u:FormItem.NoLabel="True"
|
||||
@@ -83,6 +84,7 @@
|
||||
IsChecked="{Binding IsCloseButtonVisible}"
|
||||
IsThreeState="True" />
|
||||
<CheckBox u:FormItem.Label="Modal" IsChecked="{Binding IsModal}" />
|
||||
<CheckBox u:FormItem.Label="CanDragMove" IsChecked="{Binding CanDragMove}" />
|
||||
<Button
|
||||
HorizontalAlignment="Left"
|
||||
u:FormItem.NoLabel="True"
|
||||
|
||||
@@ -31,6 +31,7 @@ public partial class DefaultWindowDialogDemoViewModel: ObservableObject
|
||||
[ObservableProperty] private DialogButton _button;
|
||||
[ObservableProperty] private bool _showInTaskBar;
|
||||
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||
[ObservableProperty] private bool _canDragMove;
|
||||
|
||||
public ICommand ShowDialogCommand { get; }
|
||||
|
||||
@@ -40,6 +41,7 @@ public partial class DefaultWindowDialogDemoViewModel: ObservableObject
|
||||
Mode = DialogMode.None;
|
||||
Button = DialogButton.OKCancel;
|
||||
Location = WindowStartupLocation.CenterScreen;
|
||||
CanDragMove = true;
|
||||
}
|
||||
|
||||
private async Task ShowDialog()
|
||||
@@ -52,6 +54,7 @@ public partial class DefaultWindowDialogDemoViewModel: ObservableObject
|
||||
ShowInTaskBar = ShowInTaskBar,
|
||||
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||
StartupLocation = Location,
|
||||
CanDragMove = CanDragMove,
|
||||
};
|
||||
if (X.HasValue && Y.HasValue)
|
||||
{
|
||||
@@ -70,6 +73,7 @@ public partial class CustomWindowDialogDemoViewModel: ObservableObject
|
||||
[ObservableProperty] private bool _showInTaskBar;
|
||||
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||
[ObservableProperty] private bool _isModal;
|
||||
[ObservableProperty] private bool _canDragMove;
|
||||
|
||||
public ICommand ShowDialogCommand { get; }
|
||||
|
||||
@@ -78,6 +82,7 @@ public partial class CustomWindowDialogDemoViewModel: ObservableObject
|
||||
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||
Location = WindowStartupLocation.CenterScreen;
|
||||
IsModal = true;
|
||||
CanDragMove = true;
|
||||
}
|
||||
|
||||
private async Task ShowDialog()
|
||||
@@ -88,6 +93,7 @@ public partial class CustomWindowDialogDemoViewModel: ObservableObject
|
||||
ShowInTaskBar = ShowInTaskBar,
|
||||
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||
StartupLocation = Location,
|
||||
CanDragMove = CanDragMove,
|
||||
};
|
||||
if (X.HasValue && Y.HasValue)
|
||||
{
|
||||
|
||||
@@ -15,13 +15,14 @@ public static class Dialog
|
||||
/// <typeparam name="TView"></typeparam>
|
||||
/// <typeparam name="TViewModel"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static void ShowCustom<TView, TViewModel>(TViewModel? vm, Window? owner = null, DialogOptions? options = null)
|
||||
public static void ShowCustom<TView, TViewModel>(TViewModel? vm, Window? owner = null,
|
||||
DialogOptions? options = null)
|
||||
where TView : Control, new()
|
||||
{
|
||||
var window = new DialogWindow
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -48,7 +49,7 @@ public static class Dialog
|
||||
var window = new DialogWindow
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -79,7 +80,7 @@ public static class Dialog
|
||||
var window = new DefaultDialogWindow
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -88,10 +89,8 @@ public static class Dialog
|
||||
window.Show();
|
||||
return Task.FromResult(DialogResult.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
window.Icon = owner.Icon;
|
||||
}
|
||||
return window.ShowDialog<DialogResult>(owner);
|
||||
}
|
||||
|
||||
@@ -103,12 +102,13 @@ public static class Dialog
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public static Task<DialogResult> ShowModal(Control view, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
public static Task<DialogResult> ShowModal(Control view, object? vm, Window? owner = null,
|
||||
DialogOptions? options = null)
|
||||
{
|
||||
var window = new DefaultDialogWindow
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -117,10 +117,8 @@ public static class Dialog
|
||||
window.Show();
|
||||
return Task.FromResult(DialogResult.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
window.Icon = owner.Icon;
|
||||
}
|
||||
return window.ShowDialog<DialogResult>(owner);
|
||||
}
|
||||
|
||||
@@ -141,7 +139,7 @@ public static class Dialog
|
||||
var window = new DialogWindow
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -150,10 +148,8 @@ public static class Dialog
|
||||
window.Show();
|
||||
return Task.FromResult(default(TResult));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
window.Icon = owner.Icon;
|
||||
}
|
||||
return window.ShowDialog<TResult?>(owner);
|
||||
}
|
||||
|
||||
@@ -172,7 +168,7 @@ public static class Dialog
|
||||
var window = new DialogWindow
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDialogWindow(window, options);
|
||||
owner ??= GetMainWindow();
|
||||
@@ -181,11 +177,8 @@ public static class Dialog
|
||||
window.Show();
|
||||
return Task.FromResult(default(TResult));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
window.Icon = owner.Icon;
|
||||
}
|
||||
return window.ShowDialog<TResult?>(owner);
|
||||
}
|
||||
|
||||
@@ -206,26 +199,20 @@ public static class Dialog
|
||||
/// <param name="options"></param>
|
||||
private static void ConfigureDialogWindow(DialogWindow window, DialogOptions? options)
|
||||
{
|
||||
if (options is null)
|
||||
{
|
||||
options = new DialogOptions();
|
||||
}
|
||||
if (options is null) options = new DialogOptions();
|
||||
window.WindowStartupLocation = options.StartupLocation;
|
||||
window.Title = options.Title;
|
||||
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
window.ShowInTaskbar = options.ShowInTaskBar;
|
||||
window.CanDragMove = options.CanDragMove;
|
||||
if (options.StartupLocation == WindowStartupLocation.Manual)
|
||||
{
|
||||
if (options.Position is not null)
|
||||
{
|
||||
window.Position = options.Position.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach options to default dialog window.
|
||||
@@ -241,16 +228,13 @@ public static class Dialog
|
||||
window.Mode = options.Mode;
|
||||
window.ShowInTaskbar = options.ShowInTaskBar;
|
||||
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||
window.CanDragMove = options.CanDragMove;
|
||||
if (options.StartupLocation == WindowStartupLocation.Manual)
|
||||
{
|
||||
if (options.Position is not null)
|
||||
{
|
||||
window.Position = options.Position.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class DialogWindow : Window
|
||||
|
||||
protected internal Button? _closeButton;
|
||||
private Panel? _titleArea;
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
|
||||
static DialogWindow()
|
||||
{
|
||||
@@ -45,6 +46,7 @@ public class DialogWindow : Window
|
||||
IsVisibleProperty.SetValue(IsCloseButtonVisible ?? true, _closeButton);
|
||||
Button.ClickEvent.AddHandler(OnCloseButtonClicked, _closeButton);
|
||||
_titleArea = e.NameScope.Find<Panel>(PART_TitleArea);
|
||||
IsHitTestVisibleProperty.SetValue(CanDragMove, _titleArea);
|
||||
_titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
|
||||
}
|
||||
|
||||
@@ -63,6 +65,7 @@ public class DialogWindow : Window
|
||||
|
||||
private void OnTitlePointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (CanDragMove)
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,6 @@ public class DialogOptions
|
||||
public bool? IsCloseButtonVisible { get; set; } = true;
|
||||
|
||||
public bool ShowInTaskBar { get; set; } = true;
|
||||
|
||||
public bool CanDragMove { get; set; } = true;
|
||||
}
|
||||
Reference in New Issue
Block a user