更新
This commit is contained in:
@@ -5,35 +5,35 @@ namespace WPFluent.Controls;
|
||||
|
||||
public static class Toast
|
||||
{
|
||||
public static void Information(FrameworkElement owner, string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Information, location, offsetMargin, time));
|
||||
public static void Information(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Information, offsetMargin, time));
|
||||
|
||||
public static void Information(string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Information, location, offsetMargin, time));
|
||||
public static void Information(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Information, offsetMargin, time));
|
||||
|
||||
public static void Success(FrameworkElement owner, string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Success, location, offsetMargin, time));
|
||||
public static void Success(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Success, offsetMargin, time));
|
||||
|
||||
public static void Success(string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Success, location, offsetMargin, time));
|
||||
public static void Success(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Success, offsetMargin, time));
|
||||
|
||||
public static void Error(FrameworkElement owner, string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Error, location, offsetMargin, time));
|
||||
public static void Error(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Error, offsetMargin, time));
|
||||
|
||||
public static void Error(string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Error, location, offsetMargin, time));
|
||||
public static void Error(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Error, offsetMargin, time));
|
||||
|
||||
public static void Warning(FrameworkElement owner, string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Warning, location, offsetMargin, time));
|
||||
public static void Warning(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Warning, offsetMargin, time));
|
||||
|
||||
public static void Warning(string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Warning, location, offsetMargin, time));
|
||||
public static void Warning(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Warning, offsetMargin, time));
|
||||
|
||||
public static void Question(FrameworkElement owner, string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Question, location, offsetMargin, time));
|
||||
public static void Question(FrameworkElement owner, string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(owner, message, new ToastConfig(ToastIcon.Question, offsetMargin, time));
|
||||
|
||||
public static void Question(string message, ToastLocation location = ToastLocation.TopCenter, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Question, location, offsetMargin, time));
|
||||
public static void Question(string message, Thickness offsetMargin = default, int time = ToastConfig.NormalTime)
|
||||
=> Show(null!, message, new ToastConfig(ToastIcon.Question, offsetMargin, time));
|
||||
|
||||
public static void Show(FrameworkElement owner, string message, ToastConfig? options = null)
|
||||
{
|
||||
|
||||
@@ -41,10 +41,9 @@ public sealed class ToastConfig
|
||||
{
|
||||
}
|
||||
|
||||
public ToastConfig(ToastIcon icon, ToastLocation location, Thickness offsetMargin, int time) : this()
|
||||
public ToastConfig(ToastIcon icon, Thickness offsetMargin, int time) : this()
|
||||
{
|
||||
ToastIcon = icon;
|
||||
Location = location;
|
||||
if (offsetMargin != default)
|
||||
{
|
||||
OffsetMargin = offsetMargin;
|
||||
|
||||
@@ -1,55 +1,69 @@
|
||||
<UserControl
|
||||
x:Class="WPFluent.Controls.ToastControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:conv="clr-namespace:WPFluent.Converters"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
MinWidth="50"
|
||||
MaxWidth="500"
|
||||
d:DesignHeight="35"
|
||||
d:DesignWidth="120"
|
||||
Focusable="False"
|
||||
FontSize="16"
|
||||
MaxWidth="500"
|
||||
MinWidth="50"
|
||||
Opacity="1"
|
||||
mc:Ignorable="d">
|
||||
d:DesignHeight="35"
|
||||
d:DesignWidth="120"
|
||||
mc:Ignorable="d"
|
||||
x:Class="WPFluent.Controls.ToastControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:controls="clr-namespace:WPFluent.Controls"
|
||||
xmlns:conv="clr-namespace:WPFluent.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<UserControl.Resources>
|
||||
<FontFamily x:Key="SymbolThemeFontFamily">pack://application:,,,/WPFluent;component/Resources/Fonts/Segoe Fluent Icons.ttf#Segoe Fluent Icons</FontFamily>
|
||||
</UserControl.Resources>
|
||||
<Border
|
||||
Padding="8"
|
||||
Background="{DynamicResource ApplicationBackgroundBrush}"
|
||||
Background="{DynamicResource ApplicationBackgroundColorBrush}"
|
||||
BorderBrush="{DynamicResource ControlElevationBorderBrush}"
|
||||
BorderThickness="{Binding BorderThickness}"
|
||||
CornerRadius="{Binding CornerRadius}">
|
||||
CornerRadius="{Binding CornerRadius}"
|
||||
Padding="8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Width="16"
|
||||
Height="16"
|
||||
Margin="0,0,6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
FontSize="{Binding IconSize}"
|
||||
Foreground="{Binding ToastIcon, Converter={x:Static conv:ToastIconForegroundConverter.New}}"
|
||||
Grid.Column="0"
|
||||
Height="16"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,6,0"
|
||||
Text="{Binding ToastIcon, Converter={x:Static conv:ToastIconConverter.New}}"
|
||||
Visibility="{Binding ToastIcon, Converter={x:Static conv:ToastIconVisibilityConverter.New}}" />
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{Binding ToastIcon, Converter={x:Static conv:ToastIconVisibilityConverter.New}}"
|
||||
Width="16" />
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{Binding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{Binding VerticalContentAlignment}"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
FontSize="{Binding FontSize}"
|
||||
FontStretch="{Binding FontStretch}"
|
||||
FontStyle="{Binding FontStyle}"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
Foreground="{DynamicResource TextControlForeground}"
|
||||
Text="{Binding Message}" />
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{Binding HorizontalContentAlignment}"
|
||||
Text="{Binding Message}"
|
||||
VerticalAlignment="{Binding VerticalContentAlignment}" />
|
||||
</Grid>
|
||||
<!--<controls:InfoBar
|
||||
Grid.Column="1"
|
||||
Severity="Attention"
|
||||
HorizontalAlignment="{Binding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{Binding VerticalContentAlignment}"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
FontSize="{Binding FontSize}"
|
||||
FontStretch="{Binding FontStretch}"
|
||||
FontStyle="{Binding FontStyle}"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
IsOpen="{Binding}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Message="{Binding Message}" />-->
|
||||
</Border>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -137,54 +137,55 @@ public partial class ToastControl : UserControl
|
||||
ownerWidth = SystemParameters.WorkArea.Size.Width * DpiHelper.ScaleX;
|
||||
ownerHeight = SystemParameters.WorkArea.Size.Height * DpiHelper.ScaleY;
|
||||
}
|
||||
popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
//switch (toast.Location)
|
||||
//{
|
||||
// case ToastLocation.Center:
|
||||
// popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
// popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
// break;
|
||||
|
||||
switch (toast.Location)
|
||||
{
|
||||
case ToastLocation.Center:
|
||||
popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
break;
|
||||
// case ToastLocation.Left:
|
||||
// popup.HorizontalOffset = offset.Left;
|
||||
// popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
// break;
|
||||
|
||||
case ToastLocation.Left:
|
||||
popup.HorizontalOffset = offset.Left;
|
||||
popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
break;
|
||||
// case ToastLocation.Right:
|
||||
// popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
// popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
// break;
|
||||
|
||||
case ToastLocation.Right:
|
||||
popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
popup.VerticalOffset = (ownerHeight - popupHeight) / 2d;
|
||||
break;
|
||||
// case ToastLocation.TopLeft:
|
||||
// popup.HorizontalOffset = offset.Left;
|
||||
// popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
// break;
|
||||
|
||||
case ToastLocation.TopLeft:
|
||||
popup.HorizontalOffset = offset.Left;
|
||||
popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
break;
|
||||
// case ToastLocation.TopCenter:
|
||||
// popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
// popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
// break;
|
||||
|
||||
case ToastLocation.TopCenter:
|
||||
popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
break;
|
||||
// case ToastLocation.TopRight:
|
||||
// popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
// popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
// break;
|
||||
|
||||
case ToastLocation.TopRight:
|
||||
popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
popup.VerticalOffset = toast.OffsetMargin.Top + offset.Top;
|
||||
break;
|
||||
// case ToastLocation.BottomLeft:
|
||||
// popup.HorizontalOffset = offset.Left;
|
||||
// popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
// break;
|
||||
|
||||
case ToastLocation.BottomLeft:
|
||||
popup.HorizontalOffset = offset.Left;
|
||||
popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
break;
|
||||
// case ToastLocation.BottomCenter:
|
||||
// popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
// popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
// break;
|
||||
|
||||
case ToastLocation.BottomCenter:
|
||||
popup.HorizontalOffset = (ownerWidth - popupWidth) / 2d;
|
||||
popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
break;
|
||||
|
||||
case ToastLocation.BottomRight:
|
||||
popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
break;
|
||||
}
|
||||
// case ToastLocation.BottomRight:
|
||||
// popup.HorizontalOffset = ownerWidth - popupWidth - offset.Right;
|
||||
// popup.VerticalOffset = ownerHeight - popupHeight - offset.Bottom;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
||||
Reference in New Issue
Block a user