feat: add icon, improve demo.
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||
x:DataType="vm:MessageBoxDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
x:Class="Ursa.Demo.Pages.MessageBoxDemo">
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Pages.MessageBoxDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:MessageBoxDemoViewModel"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Styles>
|
||||
<Style Selector="Button">
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="Margin" Value="8"></Setter>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<Button Content="Default" Command="{Binding DefaultMessageBoxCommand}"></Button>
|
||||
<Button Content="OK" Command="{Binding OkCommand}" ></Button>
|
||||
<Button Content="OKCancel" Command="{Binding OkCancelCommand}" ></Button>
|
||||
<Button Content="YesNo" Command="{Binding YesNoCommand}" ></Button>
|
||||
<Button Content="YesNoCancel" Command="{Binding YesNoCancelCommand}" ></Button>
|
||||
<ComboBox ItemsSource="{Binding Icons}" SelectedItem="{Binding SelectedIcon}" />
|
||||
<Button Command="{Binding DefaultMessageBoxCommand}" Content="Default" />
|
||||
<Button Command="{Binding OkCommand}" Content="OK" />
|
||||
<Button Command="{Binding OkCancelCommand}" Content="OKCancel" />
|
||||
<Button Command="{Binding YesNoCommand}" Content="YesNo" />
|
||||
<Button Command="{Binding YesNoCancelCommand}" Content="YesNoCancel" />
|
||||
|
||||
<TextBlock>
|
||||
<Run Text="Last Clicked Result: "></Run>
|
||||
<Run Text="{Binding Result}"></Run>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -13,6 +15,22 @@ public class MessageBoxDemoViewModel: ObservableObject
|
||||
public ICommand YesNoCommand { get; set; }
|
||||
public ICommand YesNoCancelCommand { get; set; }
|
||||
public ICommand OkCancelCommand { get; set; }
|
||||
|
||||
public ObservableCollection<MessageBoxIcon> Icons { get; set; }
|
||||
|
||||
private MessageBoxIcon _selectedIcon;
|
||||
public MessageBoxIcon SelectedIcon
|
||||
{
|
||||
get => _selectedIcon;
|
||||
set => SetProperty(ref _selectedIcon, value);
|
||||
}
|
||||
|
||||
private MessageBoxResult _result;
|
||||
public MessageBoxResult Result
|
||||
{
|
||||
get => _result;
|
||||
set => SetProperty(ref _result, value);
|
||||
}
|
||||
|
||||
public MessageBoxDemoViewModel()
|
||||
{
|
||||
@@ -21,30 +39,33 @@ public class MessageBoxDemoViewModel: ObservableObject
|
||||
YesNoCommand = new AsyncRelayCommand(OnYesNoAsync);
|
||||
YesNoCancelCommand = new AsyncRelayCommand(OnYesNoCancelAsync);
|
||||
OkCancelCommand = new AsyncRelayCommand(OnOkCancelAsync);
|
||||
Icons = new ObservableCollection<MessageBoxIcon>(
|
||||
Enum.GetValues<MessageBoxIcon>());
|
||||
SelectedIcon = MessageBoxIcon.None;
|
||||
}
|
||||
|
||||
private async Task OnDefaultMessageAsync()
|
||||
{
|
||||
var result = await MessageBox.ShowAsync("Hello Message Box");
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", icon: SelectedIcon);
|
||||
}
|
||||
|
||||
private async Task OnOkAsync()
|
||||
{
|
||||
var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.OK);
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button:MessageBoxButton.OK);
|
||||
}
|
||||
|
||||
private async Task OnYesNoAsync()
|
||||
{
|
||||
var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.YesNo);
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button: MessageBoxButton.YesNo);
|
||||
}
|
||||
|
||||
private async Task OnYesNoCancelAsync()
|
||||
{
|
||||
var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.YesNoCancel);
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button: MessageBoxButton.YesNoCancel);
|
||||
}
|
||||
|
||||
private async Task OnOkCancelAsync()
|
||||
{
|
||||
var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.OKCancel);
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button:MessageBoxButton.OKCancel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user