WPF 写一个提醒工具软件(完整项目)
生活随笔
收集整理的這篇文章主要介紹了
WPF 写一个提醒工具软件(完整项目)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
昨天整理硬盤時,偶然發現一個很久之前寫的小工具,一個提醒工具。
包含定時提醒,間隔提醒功能。
看看效果:
界面看起來也還湊合,還使用了HandyControl,有桌面托盤功能
界面是下面這樣的
提醒窗口有兩種,分別是這樣的:
MainWindow.xaml代碼如下:
<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>代碼很多,粘不完。
想要完整項目代碼的小伙伴掃碼關注本公眾號后回復:“提醒工具”? 獲取下載鏈接。
如果喜歡,點個贊唄~
總結
以上是生活随笔為你收集整理的WPF 写一个提醒工具软件(完整项目)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NET问答: 多个 await 和 Ta
- 下一篇: WPF实现环(圆)形菜单