WPF 写一个提醒工具软件(完整项目)

昨天整理硬盘时,偶然发现一个很久之前写的小工具,一个提醒工具。

包含定时提醒,间隔提醒功能。

界面看起来也还凑合,还使用了HandyControl,有桌面托盘功能

界面是下面这样的

 

 

 提醒窗口有两种,分别是这样的:

 

 MainWindow.xaml代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<Window x:Class="Notify.MainWindow"
        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:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Notify"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        mc:Ignorable="d"
        xmlns:hc="https://handyorg.github.io/handycontrol"
        WindowStartupLocation="CenterScreen"
        Title="定时提醒"
        AllowsTransparency="True"
        hc:WindowAttach.IgnoreAltF4="True"
        WindowStyle="None"
        Background="Transparent"
        Width="520" Height="270"
        ShowInTaskbar="False"
        Icon="./Resources/Tip32.png"
        >
    <Window.Resources>
        <ResourceDictionary>
            <!--DataGrid样式-->
            <Style TargetType="DataGrid">
                <!--网格线颜色-->
                <Setter Property="CanUserResizeColumns" Value="false"/>
                <Setter Property="Background" Value="White" />
                <Setter Property="BorderBrush" Value="Gray" />
                <Setter Property="BorderThickness" Value="0.6"/>
                <Setter Property="RowHeaderWidth" Value="0"/>
                <Setter Property="HorizontalGridLinesBrush">
                    <Setter.Value>
                        <SolidColorBrush Color="LightGray"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="VerticalGridLinesBrush">
                    <Setter.Value>
                        <SolidColorBrush Color="LightGray"/>
                    </Setter.Value>
                </Setter>
</Style>
            <!--标题栏样式-->
            <Style TargetType="DataGridColumnHeader">
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="MinHeight" Value="25" />
                <Setter Property="FontSize" Value="14" />
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="DataGridColumnHeader">
                            <Border x:Name="BackgroundBorder" Width="Auto"
                                    Background="Gray">
                                <Grid>
                                    <ContentPresenter  VerticalAlignment="Center" HorizontalAlignment="Left"/>
                                    <Rectangle Width="1" Fill="LightGray" HorizontalAlignment="Right" />
                                    <Rectangle Height="1" Fill="LightGray" VerticalAlignment="Bottom"/>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Height" Value="25"/>
</Style>
            <!--行样式触发-->
            <!--背景色改变必须先设置cellStyle 因为cellStyle会覆盖rowStyle样式-->
            <Style  TargetType="DataGridRow">
                <Setter Property="Height" Value="25"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#dddddd"/>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="#dddddd"/>
                    </Trigger>
                </Style.Triggers>
</Style>
 
            <!--单元格样式触发-->
            <Style TargetType="DataGridCell">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="DataGridCell">
                            <TextBlock TextAlignment="Left" VerticalAlignment="Center"  >
                                <ContentPresenter />
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
</Style>
       
        </ResourceDictionary>
    </Window.Resources>
    <Border BorderBrush="Gray" BorderThickness="0.8" Margin="10" Background="White">
        <Border.Effect>
            <DropShadowEffect BlurRadius="10" ShadowDepth="0" Color="Black" Opacity="0.5"/>
        </Border.Effect>
        <DockPanel>
            <!--Title Bar-->
            <Grid DockPanel.Dock="Top" Background="#2bb25c" Height="30" x:Name="TitleBar">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" RenderOptions.BitmapScalingMode="Fant" Source="./Resources/Tip32.png" Margin="6"/>
                <TextBlock Grid.Column="1" Text="提醒工具" TextAlignment="Center" VerticalAlignment="Center" FontSize="13"/>
                <Border Grid.Column="3">
                    <Border.Style>
                        <Style TargetType="Border">
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="#FF6A6A"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="False">
                                    <Setter Property="Background" Value="Transparent"/>
                                </Trigger>
                            </Style.Triggers>
</Style>
                    </Border.Style>
                    <Button Command="{Binding CloseCommand}">
                        <Button.Template>
                            <ControlTemplate>
                                <Border Background="Transparent">
                                    <Image Source="./Resources/Close12.png" RenderOptions.BitmapScalingMode="Fant"  Margin="8"/>
                                </Border>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Border>
            </Grid>
            <StackPanel Margin="15 10 15 10" >
                <CheckBox IsChecked="{Binding IntervalTipChecked}" HorizontalAlignment="Left" Content="间隔提醒" FontSize="13" Height="20"></CheckBox>
                <StackPanel Orientation="Horizontal" Margin="0 3 0 8" Visibility="{Binding IntervalTipChecked,Converter={local:BooleanToVisiblityConverter}}">
                    <RadioButton IsChecked="{Binding IntervalTime,Mode=TwoWay,Converter={local:RadioButtonToTimeConverter},ConverterParameter=30}" FontSize="14" Margin="18 0 10 0" Content="30分钟" />
                    <RadioButton IsChecked="{Binding IntervalTime,Mode=TwoWay,Converter={local:RadioButtonToTimeConverter},ConverterParameter=60}" FontSize="14" Margin="0 0 10 0" Content="1小时" />
                    <RadioButton IsChecked="{Binding IntervalTime,Mode=TwoWay,Converter={local:RadioButtonToTimeConverter},ConverterParameter=120}" FontSize="14" Margin="0 0 10 0" Content="2小时" />
                    <RadioButton IsChecked="{Binding IntervalTime,Mode=TwoWay,Converter={local:RadioButtonToTimeConverter},ConverterParameter=240}" FontSize="14" Margin="0 0 10 0" Content="4小时" />
                    <CheckBox IsChecked="{Binding IntervalTime,Mode=TwoWay,Converter={local:RadioButtonToTimeConverter},ConverterParameter=0}" FontSize="14" Margin="0 0 10 0" Content="自定义" />
                    <TextBox x:Name="txtMinute" Text="{Binding CustomText,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" GotFocus="CustomTextGotFocus" PreviewTextInput="MinutePreviewTextInput"  input:InputMethod.IsInputMethodEnabled="False" FontSize="14" Width="45"></TextBox>
                    <TextBlock FontSize="14" Margin="3 0 0 0" Text="分钟" VerticalAlignment="Center"></TextBlock>
                </StackPanel>
                <TextBlock x:Name="tipText" Text="请输入1到1440的整数" Margin="320 -8 0 -10" Visibility="Collapsed"
                               Foreground="IndianRed" FontSize="12" VerticalAlignment="Center"/>
                <CheckBox IsChecked="{Binding FixedTimeTipChecked}" HorizontalAlignment="Left" Content="定时提醒" FontSize="13" Height="20"></CheckBox>
                <StackPanel Visibility="{Binding FixedTimeTipChecked,Converter={local:BooleanToVisiblityConverter}}">
                    <TextBlock FontSize="14" Margin="18 0 0 0" Text="提醒日期"/>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=1}" FontSize="14" Margin="18 5 10 0" Content="周一" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=2}" FontSize="14" Margin="0 5 10 0" Content="周二" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=4}" FontSize="14" Margin="0 5 10 0" Content="周三" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=8}" FontSize="14" Margin="0 5 10 0" Content="周四" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=16}" FontSize="14" Margin="0 5 10 0" Content="周五" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=32}" FontSize="14" Margin="0 5 10 0" Content="周六" />
                        <CheckBox IsChecked="{Binding FixedTipDays,Converter={local:DayCheckBoxConverter},ConverterParameter=64}" FontSize="14" Margin="0 5 10 0" Content="周日" />
                    </StackPanel>
                    <TextBlock FontSize="14" Margin="18 3 0 0" Text="提醒时间"/>
                    <DataGrid ItemsSource="{Binding Tips}"
                          LoadingRow="DataGrid_LoadingRow"
                          Height="150"
                          AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                          CanUserResizeRows="False" CanUserResizeColumns="False" CanUserSortColumns="False"
                          SelectionMode="Single" SelectedItem="{Binding SelectedItem}"
                          >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <i:InvokeCommandAction Command="{Binding MouseDoubleClickCommand}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <DataGrid.ContextMenu >
                            <ContextMenu StaysOpen="True">
                                <MenuItem Command="{Binding AddTipCommand}" Header="添加"/>
                                <MenuItem Command="{Binding EditTipCommand}" Header="修改"/>
                                <MenuItem Command="{Binding DeleteTipCommand}" Header="删除"/>
                                <MenuItem Command="{Binding ClearTipsCommand}" Header="清空"/>
                            </ContextMenu>
                        </DataGrid.ContextMenu>
                        <DataGrid.Columns>
                            <DataGridTextColumn IsReadOnly="True" Binding="{Binding Index}" Header="编号" Width="60"/>
                            <DataGridTextColumn IsReadOnly="True" Binding="{Binding Time,Converter={local:TimeToHourMinuteConverter}}" Header="时间" Width="100"/>
                            <DataGridTextColumn IsReadOnly="True" Binding="{Binding Content}" Header="内容" Width="*"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </StackPanel>
                <TextBlock FontSize="14" Margin="0 20 0 10" Text="距离下次提醒"/>
                <Border Height="100" HorizontalAlignment="Center" >
                    <TextBlock Text="{Binding LeftTime,Converter={local:LeftTimeToStringConverter}}" FontSize="60" Foreground="#2bb25c" VerticalAlignment="Center"></TextBlock>
                </Border>
            </StackPanel>
            <hc:NotifyIcon Icon="/icon.ico"
                       Text="Notify"
                       Visibility="Visible">
                <hc:NotifyIcon.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding PushMainWindow2TopCommand}" Header="显示"/>
                        <MenuItem Command="hc:ControlCommands.ShutdownApp" Header="退出"/>
                    </ContextMenu>
                </hc:NotifyIcon.ContextMenu>
                <hc:Interaction.Triggers>
                    <hc:EventTrigger EventName="MouseDoubleClick">
                        <hc:EventToCommand Command="{Binding PushMainWindow2TopCommand}"/>
                    </hc:EventTrigger>
                </hc:Interaction.Triggers>
            </hc:NotifyIcon>
        </DockPanel>
    </Border>
</Window>

  

代码很多,粘不完。

 需要完整项目的添加小编微信zls20210502获取!



posted @   zls366  阅读(666)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示