7 changed files with 218 additions and 9 deletions
@ -0,0 +1,92 @@ |
|||||
|
<Window x:Class="WpfNoticeMsg.NoticeMessage" |
||||
|
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
xmlns:local="clr-namespace:WpfNoticeMsg" |
||||
|
mc:Ignorable="d" |
||||
|
AllowsTransparency="True" |
||||
|
WindowStyle="None" |
||||
|
ResizeMode="NoResize" |
||||
|
WindowStartupLocation="CenterOwner" |
||||
|
Background="Transparent" |
||||
|
Foreground="White" |
||||
|
Title="NoticeMessage" MinHeight="75" MinWidth="350"> |
||||
|
|
||||
|
|
||||
|
<WindowChrome.WindowChrome> |
||||
|
<WindowChrome GlassFrameThickness="-1" CaptionHeight="2"/> |
||||
|
</WindowChrome.WindowChrome> |
||||
|
|
||||
|
|
||||
|
<Window.Style> |
||||
|
<Style TargetType="{x:Type Window}"> |
||||
|
<Setter Property="Background" Value="Transparent"></Setter> |
||||
|
<Setter Property="Template"> |
||||
|
<Setter.Value> |
||||
|
<ControlTemplate TargetType="{x:Type Window}"> |
||||
|
<Border BorderBrush="#D7D7D7" |
||||
|
BorderThickness="1" |
||||
|
CornerRadius="6" |
||||
|
x:Name="WindowBorder"> |
||||
|
<Border.Background> |
||||
|
<SolidColorBrush Opacity="0.6" Color="Black"></SolidColorBrush> |
||||
|
</Border.Background> |
||||
|
|
||||
|
|
||||
|
<Grid x:Name="LayoutRoot" |
||||
|
Background="{TemplateBinding Background}"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="Auto" /> |
||||
|
<RowDefinition Height="*" /> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Grid x:Name="WindowTitlePanel" |
||||
|
Background="{TemplateBinding BorderBrush}" |
||||
|
Margin="0,-1,0,0"> |
||||
|
|
||||
|
<ContentPresenter Content="{TemplateBinding Tag}"></ContentPresenter> |
||||
|
</Grid> |
||||
|
<AdornerDecorator Grid.Row="1" |
||||
|
KeyboardNavigation.IsTabStop="False"> |
||||
|
<ContentPresenter Content="{TemplateBinding Content}" |
||||
|
x:Name="MainContentPresenter" |
||||
|
KeyboardNavigation.TabNavigation="Cycle" /> |
||||
|
</AdornerDecorator> |
||||
|
|
||||
|
</Grid> |
||||
|
</Border> |
||||
|
</ControlTemplate> |
||||
|
</Setter.Value> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
</Window.Style> |
||||
|
|
||||
|
<Window.Tag> |
||||
|
<Border Padding="5"> |
||||
|
<Grid> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition></ColumnDefinition> |
||||
|
<ColumnDefinition></ColumnDefinition> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<TextBlock Text="提示" FontSize="14" Padding="20 5" x:Name="txt_Title"></TextBlock> |
||||
|
|
||||
|
<Button Padding="10" Grid.Column="1" HorizontalAlignment="Right" Name="close" Click="close_Click"> |
||||
|
<Button.Template> |
||||
|
<ControlTemplate TargetType="Button"> |
||||
|
<Border Padding="{TemplateBinding Padding}"> |
||||
|
<Border.Background> |
||||
|
<SolidColorBrush Color="White" Opacity="0.01"></SolidColorBrush> |
||||
|
</Border.Background> |
||||
|
<Path Data="M0 0 10 10 M5 5 10 0 M5 5 0 10" Stroke="White" ></Path> |
||||
|
</Border> |
||||
|
</ControlTemplate> |
||||
|
</Button.Template> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
</Border> |
||||
|
|
||||
|
</Window.Tag> |
||||
|
<Grid x:Name="grid" > |
||||
|
<TextBlock Margin="20 0 20 15" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="txtMsg"></TextBlock> |
||||
|
</Grid> |
||||
|
</Window> |
@ -0,0 +1,63 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Windows; |
||||
|
using System.Windows.Controls; |
||||
|
using System.Windows.Data; |
||||
|
using System.Windows.Documents; |
||||
|
using System.Windows.Input; |
||||
|
using System.Windows.Media; |
||||
|
using System.Windows.Media.Imaging; |
||||
|
using System.Windows.Shapes; |
||||
|
|
||||
|
namespace WpfNoticeMsg |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// NoticeMessage.xaml 的交互逻辑
|
||||
|
/// </summary>
|
||||
|
public partial class NoticeMessage : Window |
||||
|
{ |
||||
|
public NoticeMessage() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 显示消息
|
||||
|
/// </summary>
|
||||
|
/// <param name="msg"></param>
|
||||
|
/// <param name="title"></param>
|
||||
|
/// <param name="sleep"></param>
|
||||
|
public static void Show(string msg, string title = "提示", int sleep = 2000) |
||||
|
{ |
||||
|
Application.Current.Dispatcher.BeginInvoke(new Action(() => |
||||
|
{ |
||||
|
NoticeMessage noticeMessage = new NoticeMessage(); |
||||
|
noticeMessage.Owner = Application.Current.MainWindow; |
||||
|
noticeMessage.txt_Title.Text = title; |
||||
|
noticeMessage.txtMsg.Text = msg; |
||||
|
|
||||
|
noticeMessage.Height= noticeMessage.grid.ActualHeight; |
||||
|
noticeMessage.Width = noticeMessage.grid.ActualWidth + 30; |
||||
|
|
||||
|
noticeMessage.Show(); |
||||
|
|
||||
|
Task.Factory.StartNew(() => |
||||
|
{ |
||||
|
Thread.Sleep(sleep); |
||||
|
Application.Current.Dispatcher.Invoke(() => |
||||
|
{ |
||||
|
noticeMessage.Close(); |
||||
|
}); |
||||
|
}); |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
private void close_Click(object sender, RoutedEventArgs e) |
||||
|
{ |
||||
|
this.Close(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp3.1</TargetFramework> |
||||
|
<UseWPF>true</UseWPF> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" /> |
||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5"> |
||||
|
<PrivateAssets>all</PrivateAssets> |
||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||
|
</PackageReference> |
||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" /> |
||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.5" /> |
||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5"> |
||||
|
<PrivateAssets>all</PrivateAssets> |
||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||
|
</PackageReference> |
||||
|
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" /> |
||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> |
||||
|
</ItemGroup> |
||||
|
</Project> |
Loading…
Reference in new issue