feat: improve dialog demo layout.
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
x:DataType="local:PlainDialogViewModel"
|
x:DataType="local:PlainDialogViewModel"
|
||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
x:Class="Ursa.Demo.Dialogs.PlainDialog">
|
x:Class="Ursa.Demo.Dialogs.PlainDialog">
|
||||||
<StackPanel>
|
<StackPanel HorizontalAlignment="Center">
|
||||||
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
||||||
<TextBlock TextWrapping="Wrap" Text="{Binding Text}"></TextBlock>
|
<TextBlock TextWrapping="Wrap" Text="{Binding Text}"></TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -6,115 +6,169 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="1200"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
x:DataType="vm:DialogDemoViewModel"
|
x:DataType="vm:DialogDemoViewModel"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid ColumnDefinitions="Auto, *">
|
<Grid ColumnDefinitions="Auto, *">
|
||||||
<TabControl Grid.Column="0" Width="300">
|
<TabControl Grid.Column="0" TabStripPlacement="Left">
|
||||||
<TabItem Header="Default">
|
<TabItem Header="Default Window Dialog">
|
||||||
<StackPanel>
|
<u:Form
|
||||||
<ToggleSwitch
|
Width="300"
|
||||||
Name="overlay"
|
Margin="16,0"
|
||||||
Content="Window/Overlay"
|
DataContext="{Binding DefaultWindowDialogDemoViewModel}"
|
||||||
IsChecked="{Binding IsWindow}"
|
LabelPosition="Top">
|
||||||
OffContent="Overlay"
|
<TextBox
|
||||||
OnContent="Window" />
|
HorizontalAlignment="Stretch"
|
||||||
<ToggleSwitch
|
u:FormItem.Label="Title"
|
||||||
Content="Global/Local"
|
Text="{Binding Title}" />
|
||||||
IsChecked="{Binding IsGlobal}"
|
<u:EnumSelector
|
||||||
IsVisible="{Binding !#overlay.IsChecked}"
|
HorizontalAlignment="Stretch"
|
||||||
OffContent="Local"
|
u:FormItem.Label="Startup Location"
|
||||||
OnContent="Global" />
|
EnumType="WindowStartupLocation"
|
||||||
<ToggleSwitch
|
Value="{Binding Location}" />
|
||||||
Name="defaultModal"
|
<u:FormItem Label="PixelPosition">
|
||||||
Content="Modal/Regular"
|
<UniformGrid Columns="2" Rows="1">
|
||||||
IsChecked="{Binding IsModal}"
|
<u:NumericIntUpDown InnerLeftContent="X" Value="{Binding X}" />
|
||||||
IsVisible="{Binding !#overlay.IsChecked}"
|
<u:NumericIntUpDown InnerLeftContent="Y" Value="{Binding Y}" />
|
||||||
OffContent="Regular"
|
</UniformGrid>
|
||||||
OnContent="Modal" />
|
</u:FormItem>
|
||||||
<ToggleSwitch
|
<u:EnumSelector
|
||||||
Content="HideInTaskBar/ShowInTaskBar"
|
HorizontalAlignment="Stretch"
|
||||||
IsChecked="{Binding ShowInTaskBar}"
|
u:FormItem.Label="Dialog Mode"
|
||||||
IsVisible="{Binding #overlay.IsChecked}"
|
EnumType="u:DialogMode"
|
||||||
OffContent="HideInTaskBar"
|
Value="{Binding Mode}" />
|
||||||
OnContent="ShowInTaskBar" />
|
<u:EnumSelector
|
||||||
<ToggleSwitch
|
HorizontalAlignment="Stretch"
|
||||||
Content="ClickOnMaskToClose"
|
u:FormItem.Label="Dialog Buttons"
|
||||||
IsChecked="{Binding CanLightDismiss}"
|
EnumType="u:DialogButton"
|
||||||
OffContent="No"
|
Value="{Binding Button}" />
|
||||||
OnContent="Yes" />
|
<CheckBox u:FormItem.Label="Show In Taskbar" IsChecked="{Binding ShowInTaskBar}" />
|
||||||
<ToggleSwitch
|
<CheckBox
|
||||||
Content="FullScreen"
|
u:FormItem.Label="Is Close Button Visible"
|
||||||
IsChecked="{Binding FullScreen}"
|
IsChecked="{Binding IsCloseButtonVisible}"
|
||||||
OffContent="No"
|
IsThreeState="True" />
|
||||||
OnContent="Yes" />
|
<Button
|
||||||
<StackPanel Orientation="Horizontal">
|
HorizontalAlignment="Left"
|
||||||
<TextBlock VerticalAlignment="Center" Text="Buttons" />
|
u:FormItem.NoLabel="True"
|
||||||
<u:EnumSelector EnumType="{x:Type u:DialogButton}" Value="{Binding SelectedButton}" />
|
Command="{Binding ShowDialogCommand}"
|
||||||
</StackPanel>
|
Content="Show" />
|
||||||
<StackPanel Orientation="Horizontal">
|
</u:Form>
|
||||||
<TextBlock VerticalAlignment="Center" Text="Mode" />
|
|
||||||
<u:EnumSelector EnumType="{x:Type u:DialogMode}" Value="{Binding SelectedMode}" />
|
|
||||||
</StackPanel>
|
|
||||||
<Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" />
|
|
||||||
<TextBlock>
|
|
||||||
<Run Text="Default Result: " />
|
|
||||||
<Run Text="{Binding DefaultResult, FallbackValue=''}" />
|
|
||||||
</TextBlock>
|
|
||||||
<TextBlock>
|
|
||||||
<Run Text="Dialog Date: " />
|
|
||||||
<Run Text="{Binding Date, FallbackValue=''}" />
|
|
||||||
</TextBlock>
|
|
||||||
</StackPanel>
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Custom">
|
<TabItem Header="Custom Window Dialog">
|
||||||
<StackPanel>
|
<u:Form
|
||||||
|
Width="300"
|
||||||
|
Margin="16,0"
|
||||||
|
DataContext="{Binding CustomWindowDialogDemoViewModel}"
|
||||||
|
LabelPosition="Top">
|
||||||
|
<TextBox
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Title"
|
||||||
|
Text="{Binding Title}" />
|
||||||
|
<u:EnumSelector
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Startup Location"
|
||||||
|
EnumType="WindowStartupLocation"
|
||||||
|
Value="{Binding Location}" />
|
||||||
|
<u:FormItem Label="PixelPosition">
|
||||||
|
<UniformGrid Columns="2" Rows="1">
|
||||||
|
<u:NumericIntUpDown InnerLeftContent="X" Value="{Binding X}" />
|
||||||
|
<u:NumericIntUpDown InnerLeftContent="Y" Value="{Binding Y}" />
|
||||||
|
</UniformGrid>
|
||||||
|
</u:FormItem>
|
||||||
|
<CheckBox u:FormItem.Label="Show In Taskbar" IsChecked="{Binding ShowInTaskBar}" />
|
||||||
|
<CheckBox
|
||||||
|
u:FormItem.Label="Is Close Button Visible"
|
||||||
|
IsChecked="{Binding IsCloseButtonVisible}"
|
||||||
|
IsThreeState="True" />
|
||||||
|
<CheckBox u:FormItem.Label="Modal" IsChecked="{Binding IsModal}" />
|
||||||
|
<Button
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
u:FormItem.NoLabel="True"
|
||||||
|
Command="{Binding ShowDialogCommand}"
|
||||||
|
Content="Show" />
|
||||||
|
</u:Form>
|
||||||
|
</TabItem>
|
||||||
|
<TabItem Header="Default Overlay Dialog">
|
||||||
|
<u:Form
|
||||||
|
Width="300"
|
||||||
|
Margin="16,0"
|
||||||
|
DataContext="{Binding DefaultOverlayDialogDemoViewModel}"
|
||||||
|
LabelPosition="Top">
|
||||||
|
<TextBox
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Title"
|
||||||
|
Text="{Binding Title}" />
|
||||||
|
<u:EnumSelector
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Dialog Mode"
|
||||||
|
EnumType="u:DialogMode"
|
||||||
|
Value="{Binding Mode}" />
|
||||||
|
<u:EnumSelector
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Dialog Buttons"
|
||||||
|
EnumType="u:DialogButton"
|
||||||
|
Value="{Binding Button}" />
|
||||||
|
<CheckBox
|
||||||
|
u:FormItem.Label="Is Close Button Visible"
|
||||||
|
IsChecked="{Binding IsCloseButtonVisible}"
|
||||||
|
IsThreeState="True" />
|
||||||
|
<CheckBox u:FormItem.Label="Modal" IsChecked="{Binding IsModal}" />
|
||||||
|
<CheckBox u:FormItem.Label="Can DragMove" IsChecked="{Binding CanDragMove}" />
|
||||||
|
<CheckBox u:FormItem.Label="Can LightDismiss" IsChecked="{Binding CanLightDismiss}" />
|
||||||
|
<CheckBox u:FormItem.Label="FullScreen" IsChecked="{Binding FullScreen}" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Name="overlay2"
|
u:FormItem.Label="Global/Local OverlayHost"
|
||||||
Content="Window/Overlay"
|
IsChecked="{Binding IsLocal}"
|
||||||
IsChecked="{Binding IsWindow}"
|
OffContent="Global"
|
||||||
OffContent="Overlay"
|
OnContent="Local" />
|
||||||
OnContent="Window" />
|
<Button
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
u:FormItem.NoLabel="True"
|
||||||
|
Command="{Binding ShowDialogCommand}"
|
||||||
|
Content="Show" />
|
||||||
|
</u:Form>
|
||||||
|
</TabItem>
|
||||||
|
<TabItem Header="Custom Overlay Dialog">
|
||||||
|
<u:Form
|
||||||
|
Width="300"
|
||||||
|
Margin="16,0"
|
||||||
|
DataContext="{Binding CustomOverlayDialogDemoViewModel}"
|
||||||
|
LabelPosition="Top">
|
||||||
|
<TextBox
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Title"
|
||||||
|
Text="{Binding Title}" />
|
||||||
|
<u:EnumSelector
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Dialog Mode"
|
||||||
|
EnumType="u:DialogMode"
|
||||||
|
Value="{Binding Mode}" />
|
||||||
|
<u:EnumSelector
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
u:FormItem.Label="Dialog Buttons"
|
||||||
|
EnumType="u:DialogButton"
|
||||||
|
Value="{Binding Button}" />
|
||||||
|
<CheckBox
|
||||||
|
u:FormItem.Label="Is Close Button Visible"
|
||||||
|
IsChecked="{Binding IsCloseButtonVisible}"
|
||||||
|
IsThreeState="True" />
|
||||||
|
<CheckBox u:FormItem.Label="Modal" IsChecked="{Binding IsModal}" />
|
||||||
|
<CheckBox u:FormItem.Label="Can DragMove" IsChecked="{Binding CanDragMove}" />
|
||||||
|
<CheckBox u:FormItem.Label="Can LightDismiss" IsChecked="{Binding CanLightDismiss}" />
|
||||||
|
<CheckBox u:FormItem.Label="FullScreen" IsChecked="{Binding FullScreen}" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="Global/Local"
|
u:FormItem.Label="Global/Local OverlayHost"
|
||||||
IsChecked="{Binding IsGlobal}"
|
IsChecked="{Binding IsLocal}"
|
||||||
IsVisible="{Binding !#overlay2.IsChecked}"
|
OffContent="Global"
|
||||||
OffContent="Local"
|
OnContent="Local" />
|
||||||
OnContent="Global" />
|
<Button
|
||||||
<ToggleSwitch
|
HorizontalAlignment="Left"
|
||||||
Content="HideInTaskBar/ShowInTaskBar"
|
u:FormItem.NoLabel="True"
|
||||||
IsChecked="{Binding ShowInTaskBar}"
|
Command="{Binding ShowDialogCommand}"
|
||||||
IsVisible="{Binding #overlay2.IsChecked}"
|
Content="Show" />
|
||||||
OffContent="HideInTaskBar"
|
</u:Form>
|
||||||
OnContent="ShowInTaskBar" />
|
|
||||||
<ToggleSwitch
|
|
||||||
Name="modal"
|
|
||||||
Content="Modal/Regular"
|
|
||||||
IsChecked="{Binding IsModal}"
|
|
||||||
OffContent="Regular"
|
|
||||||
OnContent="Modal" />
|
|
||||||
<ToggleSwitch
|
|
||||||
Content="ClickOnMaskToClose"
|
|
||||||
IsChecked="{Binding CanLightDismiss}"
|
|
||||||
OffContent="No"
|
|
||||||
OnContent="Yes" />
|
|
||||||
<ToggleSwitch
|
|
||||||
Content="FullScreen"
|
|
||||||
IsChecked="{Binding FullScreen}"
|
|
||||||
OffContent="No"
|
|
||||||
OnContent="Yes" />
|
|
||||||
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Dialog" />
|
|
||||||
<TextBlock>
|
|
||||||
<Run Text="Custom Result: " />
|
|
||||||
<Run Text="{Binding Result}" />
|
|
||||||
</TextBlock>
|
|
||||||
<TextBlock>
|
|
||||||
<Run Text="Dialog Date: " />
|
|
||||||
<Run Text="{Binding Date}" />
|
|
||||||
</TextBlock>
|
|
||||||
</StackPanel>
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
<Grid Grid.Column="1">
|
<Grid Grid.Column="1">
|
||||||
@@ -122,8 +176,8 @@
|
|||||||
BorderBrush="{DynamicResource SemiGrey1}"
|
BorderBrush="{DynamicResource SemiGrey1}"
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
ClipToBounds="True"
|
ClipToBounds="True"
|
||||||
CornerRadius="20">
|
CornerRadius="12">
|
||||||
<u:OverlayDialogHost HostId="LocalHost">
|
<u:OverlayDialogHost HostId="{x:Static vm:DialogDemoViewModel.LocalHost}">
|
||||||
<u:OverlayDialogHost.DialogDataTemplates>
|
<u:OverlayDialogHost.DialogDataTemplates>
|
||||||
<DataTemplate DataType="x:String">
|
<DataTemplate DataType="x:String">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Threading.Channels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Ursa.Controls;
|
using Ursa.Controls;
|
||||||
@@ -11,129 +14,205 @@ namespace Ursa.Demo.ViewModels;
|
|||||||
|
|
||||||
public partial class DialogDemoViewModel: ObservableObject
|
public partial class DialogDemoViewModel: ObservableObject
|
||||||
{
|
{
|
||||||
public ICommand ShowDialogCommand { get; set; }
|
public const string LocalHost = "LocalHost";
|
||||||
public ICommand ShowCustomDialogCommand { get; set; }
|
public DefaultWindowDialogDemoViewModel DefaultWindowDialogDemoViewModel { get; set; } = new();
|
||||||
|
public CustomWindowDialogDemoViewModel CustomWindowDialogDemoViewModel { get; set; } = new();
|
||||||
|
public DefaultOverlayDialogDemoViewModel DefaultOverlayDialogDemoViewModel { get; set; } = new();
|
||||||
|
public CustomOverlayDialogDemoViewModel CustomOverlayDialogDemoViewModel { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
[ObservableProperty] private DialogMode _selectedMode;
|
public partial class DefaultWindowDialogDemoViewModel: ObservableObject
|
||||||
[ObservableProperty] private DialogButton _selectedButton;
|
{
|
||||||
[ObservableProperty] private bool _isWindow;
|
[ObservableProperty] private WindowStartupLocation _location;
|
||||||
[ObservableProperty] private bool _isGlobal;
|
[ObservableProperty] private int? _x;
|
||||||
[ObservableProperty] private bool _isModal;
|
[ObservableProperty] private int? _y;
|
||||||
[ObservableProperty] private bool _canLightDismiss;
|
[ObservableProperty] private string? _title;
|
||||||
[ObservableProperty] private DialogResult? _defaultResult;
|
[ObservableProperty] private DialogMode _mode;
|
||||||
[ObservableProperty] private bool _result;
|
[ObservableProperty] private DialogButton _button;
|
||||||
[ObservableProperty] private DateTime? _date;
|
|
||||||
[ObservableProperty] private bool _fullScreen;
|
|
||||||
[ObservableProperty] private bool _showInTaskBar;
|
[ObservableProperty] private bool _showInTaskBar;
|
||||||
|
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||||
public DialogDemoViewModel()
|
|
||||||
|
public ICommand ShowDialogCommand { get; }
|
||||||
|
|
||||||
|
public DefaultWindowDialogDemoViewModel()
|
||||||
{
|
{
|
||||||
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||||
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog);
|
Mode = DialogMode.None;
|
||||||
|
Button = DialogButton.OKCancel;
|
||||||
|
Location = WindowStartupLocation.CenterScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDialog()
|
||||||
|
{
|
||||||
|
var options = new DialogOptions()
|
||||||
|
{
|
||||||
|
Title = Title,
|
||||||
|
Mode = Mode,
|
||||||
|
Button = Button,
|
||||||
|
ShowInTaskBar = ShowInTaskBar,
|
||||||
|
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||||
|
StartupLocation = Location,
|
||||||
|
};
|
||||||
|
if (X.HasValue && Y.HasValue)
|
||||||
|
{
|
||||||
|
options.Position = new PixelPoint(X.Value, Y.Value);
|
||||||
|
}
|
||||||
|
await Dialog.ShowModal<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), options: options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class CustomWindowDialogDemoViewModel: ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty] private WindowStartupLocation _location;
|
||||||
|
[ObservableProperty] private int? _x;
|
||||||
|
[ObservableProperty] private int? _y;
|
||||||
|
[ObservableProperty] private string? _title;
|
||||||
|
[ObservableProperty] private bool _showInTaskBar;
|
||||||
|
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||||
|
[ObservableProperty] private bool _isModal;
|
||||||
|
|
||||||
|
public ICommand ShowDialogCommand { get; }
|
||||||
|
|
||||||
|
public CustomWindowDialogDemoViewModel()
|
||||||
|
{
|
||||||
|
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||||
|
Location = WindowStartupLocation.CenterScreen;
|
||||||
|
IsModal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDialog()
|
||||||
|
{
|
||||||
|
var options = new DialogOptions()
|
||||||
|
{
|
||||||
|
Title = Title,
|
||||||
|
ShowInTaskBar = ShowInTaskBar,
|
||||||
|
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||||
|
StartupLocation = Location,
|
||||||
|
};
|
||||||
|
if (X.HasValue && Y.HasValue)
|
||||||
|
{
|
||||||
|
options.Position = new PixelPoint(X.Value, Y.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsModal)
|
||||||
|
{
|
||||||
|
await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, object>(new DialogWithActionViewModel(),
|
||||||
|
options: options);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
|
||||||
|
options: options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class DefaultOverlayDialogDemoViewModel : ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty] private HorizontalPosition _horizontalAnchor;
|
||||||
|
[ObservableProperty] private VerticalPosition _verticalAnchor;
|
||||||
|
[ObservableProperty] private double? _horizontalOffset;
|
||||||
|
[ObservableProperty] private double? _verticalOffset;
|
||||||
|
[ObservableProperty] private bool _fullScreen;
|
||||||
|
[ObservableProperty] private DialogMode _mode;
|
||||||
|
[ObservableProperty] private DialogButton _button;
|
||||||
|
[ObservableProperty] private string? _title;
|
||||||
|
[ObservableProperty] private bool _canLightDismiss;
|
||||||
|
[ObservableProperty] private bool _canDragMove;
|
||||||
|
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||||
|
[ObservableProperty] private bool _isModal;
|
||||||
|
[ObservableProperty] private bool _isLocal;
|
||||||
|
|
||||||
|
public ICommand ShowDialogCommand { get; }
|
||||||
|
|
||||||
|
public DefaultOverlayDialogDemoViewModel()
|
||||||
|
{
|
||||||
|
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||||
|
HorizontalAnchor = HorizontalPosition.Center;
|
||||||
|
VerticalAnchor = VerticalPosition.Center;
|
||||||
|
CanDragMove = true;
|
||||||
|
IsModal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDialog()
|
||||||
|
{
|
||||||
|
var options = new OverlayDialogOptions()
|
||||||
|
{
|
||||||
|
FullScreen = FullScreen,
|
||||||
|
HorizontalAnchor = HorizontalAnchor,
|
||||||
|
VerticalAnchor = VerticalAnchor,
|
||||||
|
HorizontalOffset = HorizontalOffset,
|
||||||
|
VerticalOffset = VerticalOffset,
|
||||||
|
Mode = Mode,
|
||||||
|
Buttons = Button,
|
||||||
|
Title = Title,
|
||||||
|
CanLightDismiss = CanLightDismiss,
|
||||||
|
CanDragMove = CanDragMove,
|
||||||
|
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||||
|
};
|
||||||
|
string? dialogHostId = IsLocal ? DialogDemoViewModel.LocalHost : null;
|
||||||
|
if (IsModal)
|
||||||
|
{
|
||||||
|
await OverlayDialog.ShowModal<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), dialogHostId, options: options);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OverlayDialog.Show<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), dialogHostId, options: options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class CustomOverlayDialogDemoViewModel: ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty] private HorizontalPosition _horizontalAnchor;
|
||||||
|
[ObservableProperty] private VerticalPosition _verticalAnchor;
|
||||||
|
[ObservableProperty] private double? _horizontalOffset;
|
||||||
|
[ObservableProperty] private double? _verticalOffset;
|
||||||
|
[ObservableProperty] private bool _fullScreen;
|
||||||
|
[ObservableProperty] private DialogMode _mode;
|
||||||
|
[ObservableProperty] private DialogButton _button;
|
||||||
|
[ObservableProperty] private string? _title;
|
||||||
|
[ObservableProperty] private bool _canLightDismiss;
|
||||||
|
[ObservableProperty] private bool _canDragMove;
|
||||||
|
[ObservableProperty] private bool? _isCloseButtonVisible;
|
||||||
|
[ObservableProperty] private bool _isModal;
|
||||||
|
[ObservableProperty] private bool _isLocal;
|
||||||
|
|
||||||
|
public ICommand ShowDialogCommand { get; }
|
||||||
|
|
||||||
|
public CustomOverlayDialogDemoViewModel()
|
||||||
|
{
|
||||||
|
ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||||
|
HorizontalAnchor = HorizontalPosition.Center;
|
||||||
|
VerticalAnchor = VerticalPosition.Center;
|
||||||
|
CanDragMove = true;
|
||||||
IsModal = true;
|
IsModal = true;
|
||||||
IsGlobal = true;
|
|
||||||
ShowInTaskBar = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowDialog()
|
private async Task ShowDialog()
|
||||||
{
|
{
|
||||||
var vm = new PlainDialogViewModel();
|
var options = new OverlayDialogOptions()
|
||||||
if (IsWindow)
|
|
||||||
{
|
{
|
||||||
DefaultResult = await Dialog.ShowModal<PlainDialog, PlainDialogViewModel>(
|
FullScreen = FullScreen,
|
||||||
vm, options: new DialogOptions()
|
HorizontalAnchor = HorizontalAnchor,
|
||||||
{
|
VerticalAnchor = VerticalAnchor,
|
||||||
Title = "Please select a date",
|
HorizontalOffset = HorizontalOffset,
|
||||||
Mode = SelectedMode,
|
VerticalOffset = VerticalOffset,
|
||||||
Button = SelectedButton,
|
Mode = Mode,
|
||||||
ShowInTaskBar = ShowInTaskBar,
|
Buttons = Button,
|
||||||
});
|
Title = Title,
|
||||||
Date = vm.Date;
|
CanLightDismiss = CanLightDismiss,
|
||||||
|
CanDragMove = CanDragMove,
|
||||||
|
IsCloseButtonVisible = IsCloseButtonVisible,
|
||||||
|
};
|
||||||
|
var dialogHostId = IsLocal ? DialogDemoViewModel.LocalHost : null;
|
||||||
|
if (IsModal)
|
||||||
|
{
|
||||||
|
await OverlayDialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, object>(new DialogWithActionViewModel(), dialogHostId, options: options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IsModal)
|
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(), dialogHostId, options: options);
|
||||||
{
|
|
||||||
DefaultResult = await OverlayDialog.ShowModal<PlainDialog, PlainDialogViewModel>(
|
|
||||||
vm,
|
|
||||||
IsGlobal ? null : "LocalHost",
|
|
||||||
new OverlayDialogOptions()
|
|
||||||
{
|
|
||||||
Title = "Please select a date",
|
|
||||||
Mode = SelectedMode,
|
|
||||||
Buttons = SelectedButton,
|
|
||||||
CanLightDismiss = CanLightDismiss,
|
|
||||||
HorizontalAnchor = HorizontalPosition.Right,
|
|
||||||
HorizontalOffset = 50,
|
|
||||||
VerticalAnchor = VerticalPosition.Top,
|
|
||||||
VerticalOffset = 50,
|
|
||||||
FullScreen = FullScreen,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Date = vm.Date;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OverlayDialog.Show<PlainDialog, PlainDialogViewModel>(
|
|
||||||
new PlainDialogViewModel(),
|
|
||||||
IsGlobal ? null : "LocalHost",
|
|
||||||
new OverlayDialogOptions()
|
|
||||||
{
|
|
||||||
Title = "Please select a date",
|
|
||||||
Mode = SelectedMode,
|
|
||||||
Buttons = SelectedButton,
|
|
||||||
CanLightDismiss = CanLightDismiss,
|
|
||||||
FullScreen = FullScreen,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ShowCustomDialog()
|
|
||||||
{
|
|
||||||
var vm = new DialogWithActionViewModel();
|
|
||||||
if (IsWindow)
|
|
||||||
{
|
|
||||||
if (IsModal)
|
|
||||||
{
|
|
||||||
Result = await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
|
|
||||||
vm,
|
|
||||||
options: new DialogOptions
|
|
||||||
{
|
|
||||||
ShowInTaskBar = ShowInTaskBar
|
|
||||||
});
|
|
||||||
Date = vm.Date;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
|
|
||||||
vm,
|
|
||||||
options: new DialogOptions
|
|
||||||
{
|
|
||||||
ShowInTaskBar = ShowInTaskBar
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (IsModal)
|
|
||||||
{
|
|
||||||
Result = await OverlayDialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
|
|
||||||
vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions()
|
|
||||||
{
|
|
||||||
CanLightDismiss = CanLightDismiss,
|
|
||||||
FullScreen = FullScreen,
|
|
||||||
});
|
|
||||||
Date = vm.Date;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
|
|
||||||
IsGlobal ? null : "LocalHost",
|
|
||||||
options: new OverlayDialogOptions{ CanLightDismiss = CanLightDismiss, FullScreen = FullScreen});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Irihi.Avalonia.Shared.Contracts;
|
using Irihi.Avalonia.Shared.Contracts;
|
||||||
|
using Irihi.Avalonia.Shared.Helpers;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -8,7 +9,12 @@ public class CustomDialogControl : DialogControlBase
|
|||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
if (_closeButton is not null) _closeButton.IsVisible = IsCloseButtonVisible ?? true;
|
var closeButtonVisible = IsCloseButtonVisible ??DataContext is IDialogContext;
|
||||||
|
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
|
||||||
|
if (!closeButtonVisible)
|
||||||
|
{
|
||||||
|
OpacityProperty.SetValue(0, _closeButton);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Close()
|
public override void Close()
|
||||||
|
|||||||
@@ -70,9 +70,12 @@ public class DefaultDialogControl : DialogControlBase
|
|||||||
|
|
||||||
private void SetButtonVisibility()
|
private void SetButtonVisibility()
|
||||||
{
|
{
|
||||||
var isCloseButtonVisible =
|
var closeButtonVisible = IsCloseButtonVisible ??DataContext is IDialogContext;
|
||||||
IsCloseButtonVisible ?? (DataContext is IDialogContext || Buttons != DialogButton.YesNo);
|
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
|
||||||
IsVisibleProperty.SetValue(isCloseButtonVisible, _closeButton);
|
if (!closeButtonVisible)
|
||||||
|
{
|
||||||
|
OpacityProperty.SetValue(0, _closeButton);
|
||||||
|
}
|
||||||
switch (Buttons)
|
switch (Buttons)
|
||||||
{
|
{
|
||||||
case DialogButton.None:
|
case DialogButton.None:
|
||||||
|
|||||||
@@ -72,9 +72,15 @@ public class DefaultDialogWindow : DialogWindow
|
|||||||
|
|
||||||
private void SetButtonVisibility()
|
private void SetButtonVisibility()
|
||||||
{
|
{
|
||||||
|
// Close button should be hidden instead if invisible to retain layout.
|
||||||
|
IsVisibleProperty.SetValue(true, _closeButton);
|
||||||
var closeButtonVisible =
|
var closeButtonVisible =
|
||||||
IsCloseButtonVisible ?? (DataContext is IDialogContext || Buttons != DialogButton.YesNo);
|
IsCloseButtonVisible ?? (DataContext is IDialogContext || Buttons != DialogButton.YesNo);
|
||||||
IsVisibleProperty.SetValue(closeButtonVisible, _closeButton);
|
IsHitTestVisibleProperty.SetValue(closeButtonVisible, _closeButton);
|
||||||
|
if (!closeButtonVisible)
|
||||||
|
{
|
||||||
|
OpacityProperty.SetValue(0, _closeButton);
|
||||||
|
}
|
||||||
switch (Buttons)
|
switch (Buttons)
|
||||||
{
|
{
|
||||||
case DialogButton.None:
|
case DialogButton.None:
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ public static class Dialog
|
|||||||
window.Buttons = options.Button;
|
window.Buttons = options.Button;
|
||||||
window.Mode = options.Mode;
|
window.Mode = options.Mode;
|
||||||
window.ShowInTaskbar = options.ShowInTaskBar;
|
window.ShowInTaskbar = options.ShowInTaskBar;
|
||||||
|
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||||
if (options.StartupLocation == WindowStartupLocation.Manual)
|
if (options.StartupLocation == WindowStartupLocation.Manual)
|
||||||
{
|
{
|
||||||
if (options.Position is not null)
|
if (options.Position is not null)
|
||||||
|
|||||||
@@ -16,40 +16,50 @@ public enum VerticalPosition
|
|||||||
|
|
||||||
public class OverlayDialogOptions
|
public class OverlayDialogOptions
|
||||||
{
|
{
|
||||||
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
|
internal static OverlayDialogOptions Default { get; } = new();
|
||||||
public bool FullScreen { get; set; }
|
public bool FullScreen { get; set; }
|
||||||
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>
|
/// <summary>
|
||||||
/// This attribute is only used when HorizontalAnchor is not Center
|
/// This attribute is only used when HorizontalAnchor is not Center
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? HorizontalOffset { get; set; } = null;
|
public double? HorizontalOffset { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This attribute is only used when VerticalAnchor is not Center
|
/// This attribute is only used when VerticalAnchor is not Center
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? VerticalOffset { get; set; } = null;
|
public double? VerticalOffset { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only works for DefaultDialogControl
|
/// Only works for DefaultDialogControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DialogMode Mode { get; set; } = DialogMode.None;
|
public DialogMode Mode { get; set; } = DialogMode.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only works for DefaultDialogControl
|
/// Only works for DefaultDialogControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only works for DefaultDialogControl
|
/// Only works for DefaultDialogControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Title { get; set; } = null;
|
public string? Title { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only works for CustomDialogControl
|
/// Only works for CustomDialogControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? IsCloseButtonVisible { get; set; } = true;
|
public bool? IsCloseButtonVisible { get; set; } = true;
|
||||||
[Obsolete()]
|
|
||||||
public bool ShowCloseButton { get; set; } = true;
|
[Obsolete] 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;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The hash code of the top level dialog host. This is used to identify the dialog host if there are multiple dialog hosts with the same id. If this is not provided, the dialog will be added to the first dialog host with the same id.
|
/// The hash code of the top level dialog host. This is used to identify the dialog host if there are multiple dialog
|
||||||
|
/// hosts with the same id. If this is not provided, the dialog will be added to the first dialog host with the same
|
||||||
|
/// id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? TopLevelHashCode { get; set; }
|
public int? TopLevelHashCode { get; set; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user