feat: long message compatibility.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
</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" />
|
||||
|
||||
@@ -10,6 +10,12 @@ 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; }
|
||||
@@ -32,6 +38,33 @@ public class MessageBoxDemoViewModel: ObservableObject
|
||||
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);
|
||||
@@ -42,30 +75,31 @@ public class MessageBoxDemoViewModel: ObservableObject
|
||||
Icons = new ObservableCollection<MessageBoxIcon>(
|
||||
Enum.GetValues<MessageBoxIcon>());
|
||||
SelectedIcon = MessageBoxIcon.None;
|
||||
_message = _shortMessage;
|
||||
}
|
||||
|
||||
private async Task OnDefaultMessageAsync()
|
||||
{
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", icon: SelectedIcon);
|
||||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon);
|
||||
}
|
||||
|
||||
private async Task OnOkAsync()
|
||||
{
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button:MessageBoxButton.OK);
|
||||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OK);
|
||||
}
|
||||
|
||||
private async Task OnYesNoAsync()
|
||||
{
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button: MessageBoxButton.YesNo);
|
||||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNo);
|
||||
}
|
||||
|
||||
private async Task OnYesNoCancelAsync()
|
||||
{
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button: MessageBoxButton.YesNoCancel);
|
||||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button: MessageBoxButton.YesNoCancel);
|
||||
}
|
||||
|
||||
|
||||
private async Task OnOkCancelAsync()
|
||||
{
|
||||
Result = await MessageBox.ShowAsync("Hello Message Box", "Hello", icon: SelectedIcon, button:MessageBoxButton.OKCancel);
|
||||
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:MessageBoxButton.OKCancel);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="0" />
|
||||
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
|
||||
<Setter Property="SystemDecorations" Value="BorderOnly" />
|
||||
<Setter Property="CanResize" Value="True" />
|
||||
<Setter Property="CanResize" Value="False" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:MessageBoxWindow">
|
||||
<Panel>
|
||||
@@ -57,6 +57,7 @@
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
MaxWidth="{DynamicResource MessageBoxWindowContentMaxWidth}"
|
||||
ColumnDefinitions="Auto, *">
|
||||
<PathIcon
|
||||
Name="PART_Icon"
|
||||
@@ -65,14 +66,18 @@
|
||||
Height="24"
|
||||
Margin="0,0,12,0"
|
||||
VerticalAlignment="Center" />
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
<ScrollViewer
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
||||
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"
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
<StreamGeometry x:Key="MessageBoxWindowWarningIconGlyph">M10.2268 2.3986L1.52616 19.0749C0.831449 20.4064 1.79747 22 3.29933 22H20.7007C22.2025 22 23.1686 20.4064 22.4739 19.0749L13.7732 2.3986C13.0254 0.965441 10.9746 0.965442 10.2268 2.3986ZM13.1415 14.0101C13.0603 14.5781 12.5739 15 12.0001 15C11.4263 15 10.9398 14.5781 10.8586 14.0101L10.2829 9.97992C10.1336 8.93495 10.9445 8.00002 12.0001 8.00002C13.0556 8.00002 13.8665 8.93495 13.7172 9.97992L13.1415 14.0101ZM13.5001 18.5C13.5001 19.3284 12.8285 20 12.0001 20C11.1716 20 10.5001 19.3284 10.5001 18.5C10.5001 17.6716 11.1716 17 12.0001 17C12.8285 17 13.5001 17.6716 13.5001 18.5Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="MessageBoxWindowErrorIconGlyph">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.0352 16.8626C16.4597 17.4585 15.5101 17.4751 14.9142 16.8996L12.0368 14.121L9.25822 16.9984C8.68274 17.5943 7.73314 17.6109 7.13722 17.0354C6.5413 16.4599 6.52472 15.5103 7.1002 14.9144L9.87883 12.037L7.00147 9.2584C6.40555 8.68293 6.38897 7.73332 6.96445 7.1374C7.53992 6.54148 8.48953 6.52491 9.08545 7.10038L11.9628 9.87901L14.7414 7.00165C15.3169 6.40573 16.2665 6.38916 16.8624 6.96463C17.4584 7.54011 17.4749 8.48971 16.8995 9.08563L14.1208 11.963L16.9982 14.7416C17.5941 15.3171 17.6107 16.2667 17.0352 16.8626Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="MessageBoxWindowSuccessIconGlyph">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.8831 9.82235L11.6854 17.4112C11.4029 17.7806 10.965 17.9981 10.5 18C10.035 18.0019 9.59533 17.788 9.30982 17.421L5.81604 13.4209C5.30744 12.767 5.42524 11.8246 6.07916 11.316C6.73308 10.8074 7.67549 10.9252 8.1841 11.5791L10.4838 14.0439L15.5 8C16.0032 7.34193 16.9446 7.21641 17.6027 7.71964C18.2608 8.22287 18.3863 9.16428 17.8831 9.82235Z</StreamGeometry>
|
||||
<x:Double x:Key="MessageBoxWindowContentMaxWidth">300</x:Double>
|
||||
</ResourceDictionary>
|
||||
|
||||
Reference in New Issue
Block a user