跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
修改UI/Controls/Window/DefaultWindow.cs+122 −2看文件
@@ -7,16 +7,55 @@ using System.Runtime.InteropServices;
77using System.Text;
88using System.Threading.Tasks;
99using System.Windows;
10新增:using System.Windows.Controls;
1011using System.Windows.Input;
1112using System.Windows.Interop;
1213using System.Windows.Media;
14新增:using System.Windows.Media.Animation;
1315using System.Windows.Media.Imaging;
16新增:using System.Windows.Threading;
1417
1518namespace UI.Controls.Window
1619{
1720 public class DefaultWindow : System.Windows.Window
1821 {
1922 #region 1.依赖属性
23新增: public static readonly DependencyProperty IsShowToastDeproperty = DependencyProperty.Register("IsShowToast", typeof(bool), typeof(DefaultWindow), new PropertyMetadata(false, new PropertyChangedCallback(OnIsShowToastChanged)));
24新增: public bool IsShowToast { get { return (bool)GetValue(IsShowToastDeproperty); } set { SetValue(IsShowToastDeproperty, value); } }
25新增: private static void OnIsShowToastChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
26新增: {
27新增: var that = d as DefaultWindow;
28新增: if (that != null)
29新增: {
30新增: if (that.IsShowToast)
31新增: {
32新增: that.ShowToast();
33新增: }
34新增: else
35新增: {
36新增: that.HideToast();
37新增: }
38新增: }
39新增: }
40新增:
41新增: public static readonly DependencyProperty ToastIconProperty = DependencyProperty.Register("ToastIcon", typeof(Base.IconTypes), typeof(DefaultWindow));
42新增: public Base.IconTypes ToastIcon
43新增: {
44新增: get
45新增: {
46新增: return (Base.IconTypes)GetValue(ToastIconProperty);
47新增: }
48新增: set { SetValue(ToastIconProperty, value); }
49新增: }
50新增: public static readonly DependencyProperty ToastContentProperty = DependencyProperty.Register("ToastContent", typeof(string), typeof(DefaultWindow));
51新增: /// <summary>
52新增: /// toast content
53新增: /// </summary>
54新增: public string ToastContent
55新增: {
56新增: get { return (string)GetValue(ToastContentProperty); }
57新增: set { SetValue(ToastContentProperty, value); }
58新增: }
2059
2160 public static readonly DependencyProperty PageContainerProperty = DependencyProperty.Register("PageContainer", typeof(PageContainer), typeof(DefaultWindow), new PropertyMetadata(null, new PropertyChangedCallback(OnPageContainerChanged)));
2261 public PageContainer PageContainer { get { return (PageContainer)GetValue(PageContainerProperty); } set { SetValue(PageContainerProperty, value); } }
@@ -108,11 +147,11 @@ namespace UI.Controls.Window
108147 #endregion
109148
110149
111删除: public static readonly DependencyProperty IsCanBackProperty = DependencyProperty.Register("IsCanBack", typeof(bool), typeof(DefaultWindow), new PropertyMetadata(false,new PropertyChangedCallback(OnIsCanBackChanged)));
150新增: public static readonly DependencyProperty IsCanBackProperty = DependencyProperty.Register("IsCanBack", typeof(bool), typeof(DefaultWindow), new PropertyMetadata(false, new PropertyChangedCallback(OnIsCanBackChanged)));
112151
113152 private static void OnIsCanBackChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
114153 {
115删除: var that=d as DefaultWindow;
154新增: var that = d as DefaultWindow;
116155 if (that != null)
117156 {
118157 if (that.IsCanBack)
@@ -138,6 +177,9 @@ namespace UI.Controls.Window
138177 /// </summary>
139178 public bool IsWindowClosed { get { return IsWindowClosed_; } }
140179
180新增: private Border ToastBorder, Masklayer;
181新增: private Grid ToastGrid;
182新增: private DispatcherTimer toastTimer;
141183 #region 3.初始化
142184 public DefaultWindow()
143185 {
@@ -159,6 +201,14 @@ namespace UI.Controls.Window
159201 }
160202
161203 Loaded += new RoutedEventHandler(window_Loaded);
204新增:
205新增: toastTimer = new DispatcherTimer();
206新增: toastTimer.Tick += (s, e) =>
207新增: {
208新增: toastTimer.Stop();
209新增: IsShowToast = false;
210新增: };
211新增: toastTimer.Interval = new TimeSpan(0, 0, 3);
162212 }
163213
164214 private void OnBackCommand(object sender, ExecutedRoutedEventArgs e)
@@ -206,6 +256,10 @@ namespace UI.Controls.Window
206256 public override void OnApplyTemplate()
207257 {
208258 base.OnApplyTemplate();
259新增:
260新增: ToastBorder = GetTemplateChild("ToastBorder") as Border;
261新增: Masklayer = GetTemplateChild("Masklayer") as Border;
262新增: ToastGrid = GetTemplateChild("ToastGrid") as Grid;
209263 }
210264
211265
@@ -265,6 +319,72 @@ namespace UI.Controls.Window
265319
266320 #endregion
267321
322新增: private void ShowToast()
323新增: {
324新增: ToastGrid.Visibility = Visibility.Visible;
325新增:
326新增: Storyboard storyboard = new Storyboard();
327新增:
328新增: DoubleAnimation scrollAnimation = new DoubleAnimation();
329新增: scrollAnimation.From = -150;
330新增: scrollAnimation.To = 0;
331新增:
332新增: scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
333新增: Storyboard.SetTarget(scrollAnimation, ToastBorder);
334新增: Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].Y"));
335新增: scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.35));
336新增:
337新增: DoubleAnimation opacityAnimation = new DoubleAnimation();
338新增: opacityAnimation.To = 0.6;
339新增: opacityAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
340新增: Storyboard.SetTarget(opacityAnimation, Masklayer);
341新增: Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
342新增: opacityAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.25));
343新增: storyboard.Completed += (e, c) =>
344新增: {
345新增: toastTimer.Start();
346新增: ToastGrid.MouseLeftButtonDown += ToastGrid_MouseLeftButtonDown;
347新增: };
348新增: storyboard.Children.Add(scrollAnimation);
349新增: storyboard.Children.Add(opacityAnimation);
350新增: storyboard.Begin();
351新增: }
352新增:
353新增: private void ToastGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
354新增: {
355新增: toastTimer.Stop();
356新增: IsShowToast = false;
357新增: ToastGrid.MouseLeftButtonDown -= ToastGrid_MouseLeftButtonDown;
358新增: }
359新增:
360新增: private void HideToast()
361新增: {
362新增: Storyboard storyboard = new Storyboard();
363新增:
364新增: DoubleAnimation scrollAnimation = new DoubleAnimation();
365新增: scrollAnimation.To = -150;
366新增:
367新增: scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
368新增: Storyboard.SetTarget(scrollAnimation, ToastBorder);
369新增: Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].Y"));
370新增: scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.35));
371新增:
372新增: DoubleAnimation opacityAnimation = new DoubleAnimation();
373新增: opacityAnimation.To = 0;
374新增: opacityAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
375新增: Storyboard.SetTarget(opacityAnimation, Masklayer);
376新增: Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
377新增: opacityAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.25));
378新增:
379新增: storyboard.Children.Add(scrollAnimation);
380新增: storyboard.Children.Add(opacityAnimation);
381新增: storyboard.Completed += (e, c) =>
382新增: {
383新增: ToastGrid.Visibility = Visibility.Collapsed;
384新增: };
385新增: storyboard.Begin();
386新增: }
387新增:
268388 #region 6.事件
269389
270390 protected override void OnSourceInitialized(EventArgs e)
修改UI/MainWindow.xaml+5 −2看文件
@@ -6,13 +6,16 @@
66 xmlns:local="clr-namespace:UI"
77 mc:Ignorable="d"
88 xmlns:ui="clr-namespace:UI.Controls.Window"
9删除: Title="Tai" Height="585" Width="814" MinHeight="585" MinWidth="814"
9新增: Title="Tai" Height="585" Width="815" MinHeight="585" MinWidth="814"
1010 xmlns:control="clr-namespace:UI.Controls"
1111 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
1212 xmlns:Navigation="clr-namespace:UI.Controls.Navigation"
1313 x:Name="Window"
1414 PageContainer="{Binding PageContainer}"
15删除: Icon="/Resources/Icons/tai32.ico">
15新增: Icon="/Resources/Icons/tai32.ico"
16新增: IsShowToast="{Binding IsShowToast,Mode=TwoWay}"
17新增: ToastContent="{Binding ToastContent,Mode=TwoWay}"
18新增: ToastIcon="{Binding ToastIcon}">
1619 <Grid>
1720 <!--主要功能-->
1821 <Grid>
修改UI/Models/MainWindowModel.cs+10 −0看文件
@@ -5,6 +5,7 @@ using System.Linq;
55using System.Text;
66using System.Threading.Tasks;
77using UI.Controls;
8新增:using UI.Controls.Base;
89using UI.Controls.Navigation.Models;
910
1011namespace UI.Models
@@ -77,5 +78,14 @@ namespace UI.Models
7778
7879 private List<string> IndexUriList_;
7980 public List<string> IndexUriList { get { return IndexUriList_; } set { IndexUriList_ = value; OnPropertyChanged(); } }
81新增:
82新增:
83新增: private string ToastContent_;
84新增: public string ToastContent { get { return ToastContent_; } set { ToastContent_ = value; OnPropertyChanged(); } }
85新增:
86新增: private bool IsShowToast_ = false;
87新增: public bool IsShowToast { get { return IsShowToast_; } set { IsShowToast_ = value; OnPropertyChanged(); } }
88新增: private IconTypes ToastIcon_;
89新增: public IconTypes ToastIcon { get { return ToastIcon_; } set { ToastIcon_ = value; OnPropertyChanged(); } }
8090 }
8191}
修改UI/Themes/Window/DefaultWindow.xaml+33 −4看文件
@@ -1,6 +1,7 @@
11<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3删除: xmlns:w="clr-namespace:UI.Controls.Window" xmlns:button="clr-namespace:UI.Controls.Button">
3新增: xmlns:w="clr-namespace:UI.Controls.Window" xmlns:button="clr-namespace:UI.Controls.Button"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
45 <Style x:Key="WindowSystemButton" TargetType="{x:Type Button}">
56 <Setter Property="Background" Value="Transparent"/>
67 <Setter Property="OverridesDefaultStyle" Value="True"/>
@@ -108,7 +109,7 @@
108109 <StackPanel Orientation="Horizontal" Margin="15,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center">
109110
110111 <button:IconButton Width="0" VerticalAlignment="Center" ToolTip="返回" FontSize="10" x:Name="BackBtn" Icon="Back" WindowChrome.IsHitTestVisibleInChrome="True" Command="{x:Static w:DefaultWindowCommands.BackCommand}"/>
111删除:
112新增:
112113 <Image Source="{TemplateBinding Icon}" VerticalAlignment="Center" Stretch="Uniform" Width="18"/>
113114 <TextBlock VerticalAlignment="Center" Text="{TemplateBinding Title}" IsEnabled="{TemplateBinding IsActive}" Foreground="#5c5c5c" Margin="15,0,0,0"/>
114115 </StackPanel>
@@ -171,7 +172,35 @@
171172
172173 <!--窗体内容-->
173174 <ContentPresenter Grid.Row="1"/>
175新增: <!--提醒框-->
176新增: <Grid Panel.ZIndex="999" x:Name="ToastGrid" Visibility="Collapsed">
177新增: <!--内容-->
178新增: <Border
179新增: Padding="15,15"
180新增: CornerRadius="6"
181新增: MaxWidth="320"
182新增: x:Name="ToastBorder" Background="White" HorizontalAlignment="Center" VerticalAlignment="Top" Panel.ZIndex="1000">
183新增: <Border.RenderTransform>
184新增: <TransformGroup>
185新增: <TranslateTransform Y="-150"/>
186新增: </TransformGroup>
187新增: </Border.RenderTransform>
188新增: <Border.Effect>
189新增: <DropShadowEffect BlurRadius="10" Color="Black" Opacity=".5"/>
190新增: </Border.Effect>
191新增: <Grid >
192新增: <Grid.ColumnDefinitions>
193新增: <ColumnDefinition Width="30"/>
194新增: <ColumnDefinition Width="*"/>
174195
196新增: </Grid.ColumnDefinitions>
197新增: <base:Icon IconType="{TemplateBinding ToastIcon}" VerticalAlignment="Top" Margin="0,0,10,0"/>
198新增: <TextBlock Grid.Column="1" Text="{TemplateBinding ToastContent}" VerticalAlignment="Top" TextWrapping="WrapWithOverflow"/>
199新增: </Grid>
200新增: </Border>
201新增: <!--遮罩层-->
202新增: <Border x:Name="Masklayer" Background="Black" Opacity="0"></Border>
203新增: </Grid>
175204 </Grid>
176205 </AdornerDecorator>
177206 </Border>
@@ -190,7 +219,7 @@
190219 </DoubleAnimation>
191220 </Storyboard>
192221 </VisualState>
193删除:
222新增:
194223 </VisualStateGroup>
195224 </VisualStateManager.VisualStateGroups>
196225 </Border>
@@ -211,7 +240,7 @@
211240 </Trigger>
212241 <!--<Trigger Property="IsCanBack" Value="True">
213242 <Setter TargetName="BackBtn" Property="Visibility" Value="Visible" />
214删除: </Trigger>-->
243新增: </Trigger>-->
215244 <!--<Trigger Property="WindowState" Value="Normal">
216245 <Setter TargetName="MaximizeButton" Property="Visibility" Value="Visible" />
217246 <Setter TargetName="RestoreButton" Property="Visibility" Value="Collapsed" />
修改UI/ViewModels/MainViewModel.cs+8 −0看文件
@@ -4,6 +4,7 @@ using System.Linq;
44using System.Text;
55using System.Threading.Tasks;
66using UI.Controls;
7新增:using UI.Controls.Base;
78using UI.Controls.Navigation.Models;
89using UI.Models;
910using UI.Views;
@@ -91,5 +92,12 @@ namespace UI.ViewModels
9192 });
9293 NavSelectedItem = Items[0];
9394 }
95新增:
96新增: public void Toast(string content, IconTypes icon = IconTypes.Accept)
97新增: {
98新增: ToastContent = content;
99新增: ToastIcon = icon;
100新增: IsShowToast = true;
101新增: }
94102 }
95103}