Skip to content

Commit d313812

Browse files
committed
Add legacy message with button
1 parent ad14684 commit d313812

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

Flow.Launcher/MsgWithButton.xaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<Window
2+
x:Class="Flow.Launcher.MsgWithButton"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
Title="Msg"
6+
Width="420"
7+
Height="60"
8+
Background="#ebebeb"
9+
ResizeMode="NoResize"
10+
ShowInTaskbar="False"
11+
SizeToContent="Height"
12+
Topmost="True"
13+
WindowStyle="None">
14+
<Window.Triggers>
15+
<EventTrigger RoutedEvent="Window.Loaded">
16+
<BeginStoryboard>
17+
<Storyboard>
18+
<DoubleAnimation
19+
x:Name="showAnimation"
20+
AccelerationRatio="0.2"
21+
Storyboard.TargetProperty="Top"
22+
Duration="0:0:0.3" />
23+
</Storyboard>
24+
</BeginStoryboard>
25+
</EventTrigger>
26+
</Window.Triggers>
27+
28+
<StackPanel Orientation="Vertical">
29+
<Grid
30+
Margin="5"
31+
HorizontalAlignment="Stretch"
32+
VerticalAlignment="Stretch">
33+
<Grid.ColumnDefinitions>
34+
<ColumnDefinition Width="32" />
35+
<ColumnDefinition />
36+
<ColumnDefinition Width="2.852" />
37+
<ColumnDefinition Width="13.148" />
38+
</Grid.ColumnDefinitions>
39+
<Image
40+
x:Name="imgIco"
41+
Width="32"
42+
Height="32"
43+
Margin="0 9"
44+
HorizontalAlignment="Left" />
45+
<Grid
46+
Grid.Column="1"
47+
Margin="5 0 0 0"
48+
HorizontalAlignment="Stretch"
49+
VerticalAlignment="Stretch">
50+
<Grid.RowDefinitions>
51+
<RowDefinition />
52+
<RowDefinition />
53+
</Grid.RowDefinitions>
54+
<TextBlock
55+
x:Name="tbTitle"
56+
FontSize="16"
57+
FontWeight="Medium"
58+
Foreground="#37392c">
59+
Title
60+
</TextBlock>
61+
<TextBlock
62+
x:Name="tbSubTitle"
63+
Grid.Row="1"
64+
Foreground="#8e94a4">
65+
sdfdsf
66+
</TextBlock>
67+
</Grid>
68+
<Image
69+
x:Name="imgClose"
70+
Grid.Column="2"
71+
Grid.ColumnSpan="2"
72+
Width="16"
73+
HorizontalAlignment="Right"
74+
VerticalAlignment="Top"
75+
Cursor="Hand" />
76+
</Grid>
77+
<Button
78+
x:Name="btn"
79+
Margin="5 0 5 5"
80+
HorizontalAlignment="Stretch"
81+
Content="fwafaw"
82+
Foreground="#dcdcdc" />
83+
</StackPanel>
84+
</Window>

Flow.Launcher/MsgWithButton.xaml.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.IO;
3+
using System.Windows;
4+
using System.Windows.Forms;
5+
using System.Windows.Input;
6+
using System.Windows.Media.Animation;
7+
using Flow.Launcher.Infrastructure;
8+
9+
namespace Flow.Launcher
10+
{
11+
public partial class MsgWithButton : Window
12+
{
13+
private readonly Storyboard fadeOutStoryboard = new();
14+
private bool closing;
15+
16+
public MsgWithButton()
17+
{
18+
InitializeComponent();
19+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
20+
var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this,
21+
screen.WorkingArea.Width,
22+
screen.WorkingArea.Height);
23+
Left = dipWorkingArea.X - Width;
24+
Top = dipWorkingArea.Y;
25+
showAnimation.From = dipWorkingArea.Y;
26+
showAnimation.To = dipWorkingArea.Y - Height;
27+
28+
// Create the fade out storyboard
29+
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
30+
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
31+
{
32+
AccelerationRatio = 0.2
33+
};
34+
Storyboard.SetTarget(fadeOutAnimation, this);
35+
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
36+
fadeOutStoryboard.Children.Add(fadeOutAnimation);
37+
38+
_ = LoadImageAsync();
39+
40+
imgClose.MouseUp += imgClose_MouseUp;
41+
}
42+
43+
private async System.Threading.Tasks.Task LoadImageAsync()
44+
{
45+
imgClose.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\close.png"));
46+
}
47+
48+
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
49+
{
50+
if (!closing)
51+
{
52+
closing = true;
53+
fadeOutStoryboard.Begin();
54+
}
55+
}
56+
57+
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
58+
{
59+
Close();
60+
}
61+
62+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
63+
public async void Show(string title, string buttonText, Action buttonAction, string subTitle, string iconPath)
64+
{
65+
tbTitle.Text = title;
66+
tbSubTitle.Text = subTitle;
67+
btn.Content = buttonText;
68+
btn.Click += (s, e) => buttonAction();
69+
if (string.IsNullOrEmpty(subTitle))
70+
{
71+
tbSubTitle.Visibility = Visibility.Collapsed;
72+
}
73+
74+
if (!File.Exists(iconPath))
75+
{
76+
imgIco.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"));
77+
}
78+
else
79+
{
80+
imgIco.Source = await App.API.LoadImageAsync(iconPath);
81+
}
82+
83+
Show();
84+
85+
await Dispatcher.InvokeAsync(async () =>
86+
{
87+
if (!closing)
88+
{
89+
closing = true;
90+
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
91+
}
92+
});
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)