Skip to content

Commit

Permalink
添加预提醒的部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Sep 21, 2019
1 parent 46ba7d3 commit 30b2596
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 3 deletions.
Binary file added src/Project1.UI/Assets/Images/sunglasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions src/Project1.UI/Controls/Project1UIToast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Project1.UI.Controls
{
public class Project1UIToast : Window
{
#region 依赖属性
#region 消息
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(Project1UIToast));
/// <summary>
/// 消息
/// </summary>
public string Message
{
get { return (string)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
#endregion
#region 副标题
public static readonly DependencyProperty SubtitleProperty = DependencyProperty.Register("Subtitle", typeof(string), typeof(Project1UIToast));
/// <summary>
/// 消息
/// </summary>
public string Subtitle
{
get { return (string)GetValue(SubtitleProperty); }
set { SetValue(SubtitleProperty, value); }
}
#endregion
#endregion

private StackPanel buttonsPanel;

public Project1UIToast()
{
this.DefaultStyleKey = typeof(Project1UIToast);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
buttonsPanel = GetTemplateChild("buttonsPanel") as StackPanel;
}
private void CreateButtons(string[] buttons)
{
if (buttonsPanel != null)
{
foreach (string name in buttons)
{
var btn = new Project1UIButton();
btn.Content = name;
buttonsPanel.Children.Add(btn);
}
}
}
public void Alert(string title, string message,
string subtitle = "",
int duration = 0,
string[] buttons = null)
{

this.Title = title;
this.Message = message;
this.Subtitle = subtitle;
this.Loaded += (e, c) =>
{
this.Visibility = Visibility.Visible;
CreateButtons(buttons);
};
this.Show();
}
}
}
8 changes: 8 additions & 0 deletions src/Project1.UI/Project1.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Controls\Project1UIProcessBar.cs" />
<Compile Include="Controls\Project1UIButton.cs" />
<Compile Include="Controls\Project1UIInput.cs" />
<Compile Include="Controls\Project1UIToast.cs" />
<Compile Include="Controls\Project1UIWindow.cs" />
<Compile Include="Controls\Commands\Project1UIInputCommands.cs" />
<Compile Include="Controls\Commands\Project1UIWindowCommands.cs" />
Expand Down Expand Up @@ -200,6 +201,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Project1UIToast.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Project1UIChart.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -241,5 +246,8 @@
<ItemGroup>
<Folder Include="Controls\Models\" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\Images\sunglasses.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion src/Project1.UI/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ResourceDictionary Source="/Project1.UI;component/Themes/Project1UIIcon.xaml"/>
<ResourceDictionary Source="/Project1.UI;component/Themes/Project1UIChart.xaml"/>
<ResourceDictionary Source="/Project1.UI;component/Themes/Project1UIKeyboardInput.xaml"/>

<ResourceDictionary Source="/Project1.UI;component/Themes/Project1UIToast.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
66 changes: 66 additions & 0 deletions src/Project1.UI/Themes/Project1UIToast.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Project1.UI.Controls"
>




<Style TargetType="{x:Type controls:Project1UIToast}">
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
<Setter Property="SnapsToDevicePixels" Value="False" />
<Setter Property="Width" Value="384" />
<Setter Property="Height" Value="160" />
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="ShowInTaskbar" Value="False" />
<Setter Property="Topmost" Value="True" />
<Setter Property="Visibility" Value="Collapsed" />

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Project1UIToast}">
<Border Background="{TemplateBinding Background}" Margin="10" BorderBrush="#ABADB3" BorderThickness="1">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity=".2" BlurRadius="16"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<!--header-->
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--icon-->
<Image Grid.Column="0" Source="/Project1.UI;component/Assets/Images/sunglasses.png" Width="15" VerticalAlignment="Center" HorizontalAlignment="Center" />


<TextBlock Grid.Column="1" Text="{TemplateBinding Title}" VerticalAlignment="Center" FontSize="14" FontWeight="Bold"/>
</Grid>
<!--content-->
<StackPanel Margin="48,0,0,0" Grid.Row="1">
<TextBlock Text="{TemplateBinding Subtitle}" FontSize="14" FontWeight="Bold"/>
<TextBlock Margin="0,5,0,0" Text="{TemplateBinding Message}" FontSize="14"/>
</StackPanel>
<!--buttons-->
<StackPanel x:Name="buttonsPanel" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10">

</StackPanel>


</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>

</Style>


</ResourceDictionary>
8 changes: 6 additions & 2 deletions src/ProjectEye/Core/Service/MainService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ProjectEye.ViewModels;
using Project1.UI.Controls;
using ProjectEye.ViewModels;
using ProjectEye.Views;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -74,7 +75,10 @@ public MainService(App app,
this.cache = cache;
this.statistic = statistic;


app.OnServiceInitialized += () =>
{
new Project1UIToast().Alert("休息提醒", "这是一条通知", "即将进入休息", 3, new string[] { "好的", "暂时不" });
};
app.Exit += new ExitEventHandler(app_Exit);
}

Expand Down
16 changes: 16 additions & 0 deletions src/ProjectEye/Core/Service/PreAlertService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectEye.Core.Service
{
public class PreAlertService : IService
{
public void Init()
{

}
}
}
1 change: 1 addition & 0 deletions src/ProjectEye/ProjectEye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="Core\Service\IService.cs" />
<Compile Include="Core\Service\KeyboardShortcutsService.cs" />
<Compile Include="Core\Service\MainService.cs" />
<Compile Include="Core\Service\PreAlertService.cs" />
<Compile Include="Core\Service\ResetService.cs" />
<Compile Include="Core\Service\ScreenService.cs" />
<Compile Include="Core\Service\ServiceCollection.cs" />
Expand Down

0 comments on commit 30b2596

Please sign in to comment.