feat: add new dialog samples.
This commit is contained in:
83
demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml
Normal file
83
demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml
Normal file
@@ -0,0 +1,83 @@
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Dialogs.CustomDemoDialog"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dialogs="clr-namespace:Ursa.Demo.Dialogs"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:DataType="dialogs:CustomDemoDialogViewModel"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Background>
|
||||
<LinearGradientBrush StartPoint="5%, 5%" EndPoint="80%, 80%">
|
||||
<GradientStop Offset="0.0" Color="{DynamicResource SemiBlue0Color}" />
|
||||
<GradientStop Offset="0.4" Color="{DynamicResource SemiBlue2Color}" />
|
||||
<GradientStop Offset="0.9" Color="{DynamicResource SemiBlue1Color}" />
|
||||
</LinearGradientBrush>
|
||||
</UserControl.Background>
|
||||
<Grid Margin="24" RowDefinitions="Auto, *, Auto" MinWidth="400">
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Margin="8"
|
||||
FontSize="16"
|
||||
FontWeight="600"
|
||||
Text="Add New" />
|
||||
<u:Form
|
||||
Grid.Row="1"
|
||||
Margin="24"
|
||||
HorizontalAlignment="Stretch"
|
||||
LabelPosition="Top">
|
||||
<u:Form.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid ColumnDefinitions="Auto, *" RowDefinitions="Auto, *" />
|
||||
</ItemsPanelTemplate>
|
||||
</u:Form.ItemsPanel>
|
||||
<u:FormItem Label="Country/Region">
|
||||
<ComboBox
|
||||
Width="120"
|
||||
ItemsSource="{Binding Cities}"
|
||||
SelectedItem="{Binding City}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="32,8,0,8"
|
||||
Label="Owner">
|
||||
<TextBox u:FormItem.Label="Owner" Text="{Binding Owner}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Label="Target">
|
||||
<ComboBox
|
||||
Width="120"
|
||||
ItemsSource="{Binding Cities}"
|
||||
SelectedItem="{Binding Target}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="32,8,0,8"
|
||||
Label="Department">
|
||||
<TextBox Text="{Binding Department}" />
|
||||
</u:FormItem>
|
||||
</u:Form>
|
||||
<StackPanel
|
||||
Grid.Row="2"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Button Command="{Binding DialogCommand}" Content="Dialog" />
|
||||
<Button Command="{Binding OKCommand}" Content="OK" />
|
||||
<Button Command="{Binding CancelCommand}" Content="Cancel" />
|
||||
<ComboBox>
|
||||
<ComboBoxItem>A</ComboBoxItem>
|
||||
<ComboBoxItem>B</ComboBoxItem>
|
||||
<ComboBoxItem>C</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
13
demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs
Normal file
13
demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Ursa.Demo.Dialogs;
|
||||
|
||||
public partial class CustomDemoDialog : UserControl
|
||||
{
|
||||
public CustomDemoDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
59
demo/Ursa.Demo/Dialogs/CustomDemoDialogViewModel.cs
Normal file
59
demo/Ursa.Demo/Dialogs/CustomDemoDialogViewModel.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Irihi.Avalonia.Shared.Contracts;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.Dialogs;
|
||||
|
||||
public partial class CustomDemoDialogViewModel : ObservableObject, IDialogContext
|
||||
{
|
||||
[ObservableProperty] private string? _city;
|
||||
[ObservableProperty] private string? _department;
|
||||
[ObservableProperty] private string? _owner;
|
||||
[ObservableProperty] private string? _target;
|
||||
|
||||
public CustomDemoDialogViewModel()
|
||||
{
|
||||
Cities =
|
||||
[
|
||||
"Shanghai", "Beijing", "Hulunbuir", "Shenzhen", "Hangzhou", "Nanjing", "Chengdu", "Wuhan", "Chongqing",
|
||||
"Suzhou", "Tianjin", "Xi'an", "Qingdao", "Dalian"
|
||||
];
|
||||
OKCommand = new RelayCommand(OK);
|
||||
CancelCommand = new RelayCommand(Cancel);
|
||||
DialogCommand = new AsyncRelayCommand(ShowDialog);
|
||||
}
|
||||
|
||||
public ObservableCollection<string> Cities { get; set; }
|
||||
|
||||
public void Close()
|
||||
{
|
||||
RequestClose?.Invoke(this, null);
|
||||
}
|
||||
|
||||
public event EventHandler<object?>? RequestClose;
|
||||
|
||||
public ICommand OKCommand { get; set; }
|
||||
public ICommand CancelCommand { get; set; }
|
||||
|
||||
public ICommand DialogCommand { get; set; }
|
||||
|
||||
private void OK()
|
||||
{
|
||||
RequestClose?.Invoke(this, true);
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
RequestClose?.Invoke(this, false);
|
||||
}
|
||||
|
||||
private async Task ShowDialog()
|
||||
{
|
||||
await OverlayDialog.ShowCustomModal<CustomDemoDialog, CustomDemoDialogViewModel, bool>(new CustomDemoDialogViewModel());
|
||||
}
|
||||
}
|
||||
50
demo/Ursa.Demo/Dialogs/DefaultDemoDialog.axaml
Normal file
50
demo/Ursa.Demo/Dialogs/DefaultDemoDialog.axaml
Normal file
@@ -0,0 +1,50 @@
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Dialogs.DefaultDemoDialog"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dialogs="clr-namespace:Ursa.Demo.Dialogs"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
MinWidth="400"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:DataType="dialogs:DefaultDemoDialogViewModel"
|
||||
mc:Ignorable="d">
|
||||
<u:Form HorizontalAlignment="Stretch" LabelPosition="Top">
|
||||
<u:Form.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid ColumnDefinitions="Auto, *" RowDefinitions="Auto, *" />
|
||||
</ItemsPanelTemplate>
|
||||
</u:Form.ItemsPanel>
|
||||
<u:FormItem Label="Country/Region">
|
||||
<ComboBox
|
||||
Width="120"
|
||||
ItemsSource="{Binding Cities}"
|
||||
SelectedItem="{Binding City}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="32,8,0,8"
|
||||
Label="Owner">
|
||||
<TextBox u:FormItem.Label="Owner" Text="{Binding Owner}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Label="Target">
|
||||
<ComboBox
|
||||
Width="120"
|
||||
ItemsSource="{Binding Cities}"
|
||||
SelectedItem="{Binding Target}" />
|
||||
</u:FormItem>
|
||||
<u:FormItem
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="32,8,0,8"
|
||||
Label="Department">
|
||||
<TextBox Text="{Binding Department}" />
|
||||
</u:FormItem>
|
||||
</u:Form>
|
||||
</UserControl>
|
||||
13
demo/Ursa.Demo/Dialogs/DefaultDemoDialog.axaml.cs
Normal file
13
demo/Ursa.Demo/Dialogs/DefaultDemoDialog.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Ursa.Demo.Dialogs;
|
||||
|
||||
public partial class DefaultDemoDialog : UserControl
|
||||
{
|
||||
public DefaultDemoDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
31
demo/Ursa.Demo/Dialogs/DefaultDemoDialogViewModel.cs
Normal file
31
demo/Ursa.Demo/Dialogs/DefaultDemoDialogViewModel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Irihi.Avalonia.Shared.Contracts;
|
||||
|
||||
namespace Ursa.Demo.Dialogs;
|
||||
|
||||
public partial class DefaultDemoDialogViewModel: ObservableObject, IDialogContext
|
||||
{
|
||||
public ObservableCollection<string> Cities { get; set; }
|
||||
[ObservableProperty] private string? _owner;
|
||||
[ObservableProperty] private string? _department;
|
||||
[ObservableProperty] private string? _target;
|
||||
[ObservableProperty] private string? _city;
|
||||
|
||||
public DefaultDemoDialogViewModel()
|
||||
{
|
||||
Cities =
|
||||
[
|
||||
"Shanghai", "Beijing", "Hulunbuir", "Shenzhen", "Hangzhou", "Nanjing", "Chengdu", "Wuhan", "Chongqing",
|
||||
"Suzhou", "Tianjin", "Xi'an", "Qingdao", "Dalian"
|
||||
];
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
RequestClose?.Invoke(this, null);
|
||||
}
|
||||
|
||||
public event EventHandler<object?>? RequestClose;
|
||||
}
|
||||
@@ -140,16 +140,6 @@
|
||||
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}"
|
||||
|
||||
@@ -57,7 +57,7 @@ public partial class DefaultWindowDialogDemoViewModel: ObservableObject
|
||||
{
|
||||
options.Position = new PixelPoint(X.Value, Y.Value);
|
||||
}
|
||||
await Dialog.ShowModal<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), options: options);
|
||||
await Dialog.ShowModal<DefaultDemoDialog, DefaultDemoDialogViewModel>(new DefaultDemoDialogViewModel(), options: options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ public partial class CustomWindowDialogDemoViewModel: ObservableObject
|
||||
|
||||
if (IsModal)
|
||||
{
|
||||
await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, object>(new DialogWithActionViewModel(),
|
||||
await Dialog.ShowCustomModal<CustomDemoDialog, CustomDemoDialogViewModel, object>(new CustomDemoDialogViewModel(),
|
||||
options: options);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
|
||||
Dialog.ShowCustom<CustomDemoDialog, CustomDemoDialogViewModel>(new CustomDemoDialogViewModel(),
|
||||
options: options);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,8 @@ public partial class DefaultOverlayDialogDemoViewModel : ObservableObject
|
||||
VerticalAnchor = VerticalPosition.Center;
|
||||
CanDragMove = true;
|
||||
IsModal = true;
|
||||
IsCloseButtonVisible = true;
|
||||
Button = DialogButton.OKCancel;
|
||||
}
|
||||
|
||||
private async Task ShowDialog()
|
||||
@@ -153,11 +155,11 @@ public partial class DefaultOverlayDialogDemoViewModel : ObservableObject
|
||||
string? dialogHostId = IsLocal ? DialogDemoViewModel.LocalHost : null;
|
||||
if (IsModal)
|
||||
{
|
||||
await OverlayDialog.ShowModal<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), dialogHostId, options: options);
|
||||
await OverlayDialog.ShowModal<DefaultDemoDialog, DefaultDemoDialogViewModel>(new DefaultDemoDialogViewModel(), dialogHostId, options: options);
|
||||
}
|
||||
else
|
||||
{
|
||||
OverlayDialog.Show<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), dialogHostId, options: options);
|
||||
OverlayDialog.Show<DefaultDemoDialog, DefaultDemoDialogViewModel>(new DefaultDemoDialogViewModel(), dialogHostId, options: options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,8 +171,6 @@ public partial class CustomOverlayDialogDemoViewModel: ObservableObject
|
||||
[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;
|
||||
@@ -198,8 +198,6 @@ public partial class CustomOverlayDialogDemoViewModel: ObservableObject
|
||||
VerticalAnchor = VerticalAnchor,
|
||||
HorizontalOffset = HorizontalOffset,
|
||||
VerticalOffset = VerticalOffset,
|
||||
Mode = Mode,
|
||||
Buttons = Button,
|
||||
Title = Title,
|
||||
CanLightDismiss = CanLightDismiss,
|
||||
CanDragMove = CanDragMove,
|
||||
@@ -208,11 +206,11 @@ public partial class CustomOverlayDialogDemoViewModel: ObservableObject
|
||||
var dialogHostId = IsLocal ? DialogDemoViewModel.LocalHost : null;
|
||||
if (IsModal)
|
||||
{
|
||||
await OverlayDialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, object>(new DialogWithActionViewModel(), dialogHostId, options: options);
|
||||
await OverlayDialog.ShowCustomModal<CustomDemoDialog, CustomDemoDialogViewModel, object>(new CustomDemoDialogViewModel(), dialogHostId, options: options);
|
||||
}
|
||||
else
|
||||
{
|
||||
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(), dialogHostId, options: options);
|
||||
OverlayDialog.ShowCustom<CustomDemoDialog, CustomDemoDialogViewModel>(new CustomDemoDialogViewModel(), dialogHostId, options: options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user