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