forked from irihitech/Semi.Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request irihitech#65 from irihitech/messagebox
New control: Messagebox
- Loading branch information
Showing
15 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<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"> | ||
<ComboBox ItemsSource="{Binding Icons}" SelectedItem="{Binding SelectedIcon}" /> | ||
<ToggleSwitch Content="Try Long Message" IsChecked="{Binding UseLong}"></ToggleSwitch> | ||
<ToggleSwitch Content="Show Title" IsChecked="{Binding UseTitle}"></ToggleSwitch> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Ursa.Demo.ViewModels; | ||
|
||
namespace Ursa.Demo.Pages; | ||
|
||
public partial class MessageBoxDemo : UserControl | ||
{ | ||
public MessageBoxDemo() | ||
{ | ||
InitializeComponent(); | ||
this.DataContext = new MessageBoxDemoViewModel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Ursa.Controls; | ||
|
||
namespace Ursa.Demo.ViewModels; | ||
|
||
public class MessageBoxDemoViewModel: ObservableObject | ||
{ | ||
private readonly string _longMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; | ||
|
||
private readonly string _shortMessage = "Welcome to Ursa Avalonia!"; | ||
private string _message; | ||
private string _title; | ||
|
||
public ICommand DefaultMessageBoxCommand { get; set; } | ||
public ICommand OkCommand { get; set; } | ||
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); | ||
} | ||
|
||
private bool _useLong; | ||
|
||
public bool UseLong | ||
{ | ||
get => _useLong; | ||
set | ||
{ | ||
SetProperty(ref _useLong, value); | ||
_message = value ? _longMessage : _shortMessage; | ||
} | ||
} | ||
|
||
private bool _useTitle; | ||
|
||
public bool UseTitle | ||
{ | ||
get => _useTitle; | ||
set | ||
{ | ||
SetProperty(ref _useTitle, value); | ||
_title = value ? "Ursa MessageBox" : string.Empty; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
public MessageBoxDemoViewModel() | ||
{ | ||
DefaultMessageBoxCommand = new AsyncRelayCommand(OnDefaultMessageAsync); | ||
OkCommand = new AsyncRelayCommand(OnOkAsync); | ||
YesNoCommand = new AsyncRelayCommand(OnYesNoAsync); | ||
YesNoCancelCommand = new AsyncRelayCommand(OnYesNoCancelAsync); | ||
OkCancelCommand = new AsyncRelayCommand(OnOkCancelAsync); | ||
Icons = new ObservableCollection<MessageBoxIcon>( | ||
Enum.GetValues<MessageBoxIcon>()); | ||
SelectedIcon = MessageBoxIcon.None; | ||
_message = _shortMessage; | ||
} | ||
|
||
private async Task OnDefaultMessageAsync() | ||
{ | ||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon); | ||
} | ||
|
||
private async Task OnOkAsync() | ||
{ | ||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OK); | ||
} | ||
|
||
private async Task OnYesNoAsync() | ||
{ | ||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNo); | ||
} | ||
|
||
private async Task OnYesNoCancelAsync() | ||
{ | ||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNoCancel); | ||
} | ||
|
||
private async Task OnOkCancelAsync() | ||
{ | ||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OKCancel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<ResourceDictionary | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:u="https://irihi.tech/ursa"> | ||
<!-- Add Resources Here --> | ||
<ControlTheme x:Key="{x:Type u:MessageBoxWindow}" TargetType="u:MessageBoxWindow"> | ||
<Setter Property="Title" Value="{x:Null}" /> | ||
<Setter Property="Background" Value="{DynamicResource WindowDefaultBackground}" /> | ||
<Setter Property="TransparencyBackgroundFallback" Value="{DynamicResource WindowDefaultBackground}" /> | ||
<Setter Property="Foreground" Value="{DynamicResource WindowDefaultForeground}" /> | ||
<Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" /> | ||
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" /> | ||
<Setter Property="Padding" Value="48 24" /> | ||
<Setter Property="SizeToContent" Value="WidthAndHeight" /> | ||
<Setter Property="WindowStartupLocation" Value="CenterOwner" /> | ||
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="0" /> | ||
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" /> | ||
<Setter Property="SystemDecorations" Value="BorderOnly" /> | ||
<Setter Property="CanResize" Value="False" /> | ||
<Setter Property="Template"> | ||
<ControlTemplate TargetType="u:MessageBoxWindow"> | ||
<Panel> | ||
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> | ||
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" /> | ||
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" /> | ||
<Grid RowDefinitions="Auto, *, Auto"> | ||
<Grid Grid.Row="0" ColumnDefinitions="*, Auto"> | ||
<TextBlock | ||
Grid.Column="0" | ||
Margin="8,8,0,0" | ||
FontSize="14" | ||
FontWeight="Bold" | ||
TextTrimming="CharacterEllipsis" | ||
TextWrapping="NoWrap" | ||
Text="{TemplateBinding Title}" /> | ||
<!-- A temporary style copied from Semi. Will replace when I get time --> | ||
<Button | ||
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}" | ||
Grid.Column="1" | ||
Margin="0,4,4,0" | ||
Background="{DynamicResource CaptionButtonClosePointeroverBackground}" | ||
BorderBrush="{DynamicResource CaptionButtonClosePressedBackground}" | ||
Theme="{DynamicResource CaptionButton}"> | ||
<Button.Styles> | ||
<Style Selector="Button:pointerover"> | ||
<Setter Property="Foreground" Value="White" /> | ||
</Style> | ||
<Style Selector="Button:pressed"> | ||
<Setter Property="Foreground" Value="White" /> | ||
</Style> | ||
</Button.Styles> | ||
<PathIcon | ||
Width="12" | ||
Height="12" | ||
Data="{DynamicResource WindowCloseIconGlyph}" | ||
Foreground="{Binding $parent[Button].Foreground}" /> | ||
</Button> | ||
</Grid> | ||
<Grid | ||
Grid.Row="1" | ||
Margin="{TemplateBinding Padding}" | ||
MaxWidth="{DynamicResource MessageBoxWindowContentMaxWidth}" | ||
ColumnDefinitions="Auto, *"> | ||
<PathIcon | ||
Name="PART_Icon" | ||
Grid.Column="0" | ||
Width="24" | ||
Height="24" | ||
Margin="0,0,12,0" | ||
VerticalAlignment="Center" /> | ||
<ScrollViewer | ||
Grid.Column="1" | ||
MaxHeight="300" | ||
HorizontalScrollBarVisibility="Disabled" | ||
VerticalScrollBarVisibility="Auto"> | ||
<TextBlock | ||
Name="PART_ContentPresenter" | ||
VerticalAlignment="Center" | ||
Text="{TemplateBinding Content}" | ||
TextAlignment="Left" | ||
TextWrapping="Wrap" /> | ||
</ScrollViewer> | ||
</Grid> | ||
<StackPanel | ||
Grid.Row="2" | ||
Margin="0,0,8,8" | ||
HorizontalAlignment="Right" | ||
Orientation="Horizontal"> | ||
<Button | ||
Name="{x:Static u:MessageBoxWindow.PART_CancelButton}" | ||
Margin="8,0,0,0" | ||
Classes="Tertiary" | ||
Content="Cancel" /> | ||
<Button | ||
Name="{x:Static u:MessageBoxWindow.PART_NoButton}" | ||
Margin="8,0,0,0" | ||
Classes="Danger" | ||
Content="No" /> | ||
<Button | ||
Name="{x:Static u:MessageBoxWindow.PART_YesButton}" | ||
Margin="8,0,0,0" | ||
Classes="Primary" | ||
Content="Yes" /> | ||
<Button | ||
Name="{x:Static u:MessageBoxWindow.PART_OKButton}" | ||
Margin="8,0,0,0" | ||
Classes="Primary" | ||
Content="OK" /> | ||
</StackPanel> | ||
</Grid> | ||
</Panel> | ||
</ControlTemplate> | ||
</Setter> | ||
<Style Selector="^[MessageIcon=None] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="False" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Asterisk] /template/ PathIcon#PART_Icon, ^[MessageIcon=Information] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowInformationIconGlyph}" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Error] /template/ PathIcon#PART_Icon, ^[MessageIcon=Hand] /template/ PathIcon#PART_Icon, ^[MessageIcon=Stop] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiRed6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowErrorIconGlyph}" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Exclamation] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiYellow6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowWarningIconGlyph}" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Question] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiBlue6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowQuestionIconGlyph}" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Warning] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiOrange6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowWarningIconGlyph}" /> | ||
</Style> | ||
<Style Selector="^[MessageIcon=Success] /template/ PathIcon#PART_Icon"> | ||
<Setter Property="IsVisible" Value="True" /> | ||
<Setter Property="Foreground" Value="{DynamicResource SemiGreen6}" /> | ||
<Setter Property="Data" Value="{DynamicResource MessageBoxWindowSuccessIconGlyph}" /> | ||
</Style> | ||
|
||
</ControlTheme> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.