新网站建设总结,陕西省建设网三类人员成绩查询,网站模板下载器,龙岗区01—概述前几天群里有人问如何制作备忘录#xff0c;感觉这样一个小实例挺适合新手们入门学习使用#xff0c;所以就抽空做了出来。界面如下图#xff1a;这个备忘录主要包括了如下功能#xff1a;① 备忘录信息的增、删、改、查#xff1b;② 备忘录时间到了以后进行语音… 01—概述 前几天群里有人问如何制作备忘录感觉这样一个小实例挺适合新手们入门学习使用所以就抽空做了出来。界面如下图这个备忘录主要包括了如下功能① 备忘录信息的增、删、改、查② 备忘录时间到了以后进行语音播报。功能很简单但是要实现这么一个功能也涉及众多的知识点接下来详细进行分解。02—内容详述①界面button的图标图标图片可以上网上下载下载好以后放到项目目录中然后在项目中找到你的图片——右键包括在项目中——再右键点击属性复制到输出目录更改为始终复制。生成操作更改为内容。前台XMAL操作Button Margin15,5 MinWidth60 cal:Message.Attach[Event Click] [Action SearchClick] WrapPanel Image Source/Images/search.png Width15 Height15 /TextBlock Text查找 VerticalAlignmentCenter //WrapPanel/Button② 数据源这里我采用从xml读取并绑定到界面界面如果有修改在页面退出时进行数据保存当然你也可以使用数据库去操作XML文件位置根目录的RawData下XML文件数据内容如下MemorandumModel数据模型定义public class MemorandumModel {public string Title { get; set; }public EvenType EvenType { get; set; }public DateTime DateTime { get; set; }public bool IsComplete { get; set; }}③XML文件的读取和保存MemorandumRealList是我们所有数据的集合为了方便界面查询界面绑定了MemorandumShowList 这个集合xml读取public void XmlDocReader(){//XmlDocument读取xml文件XmlDocument xmlDoc new XmlDocument();xmlDoc.Load(XmlDocPath);//获取xml根节点XmlNode xmlRoot xmlDoc.DocumentElement;if (xmlRoot null)return;//读取所有的节点foreach (XmlNode node in xmlRoot.SelectNodes(MemorandumModel)){MemorandumRealList.Add(new MemorandumModel(){Title node.SelectSingleNode(Title).InnerText,EvenType (EvenType)Enum.Parse(typeof(EvenType), node.SelectSingleNode(EvenType).InnerText),DateTime Convert.ToDateTime(node.SelectSingleNode(DateTime).InnerText),IsComplete Convert.ToBoolean(node.SelectSingleNode(IsComplete).InnerText)}); }MemorandumShowList new ObservableCollectionMemorandumModel(MemorandumRealList);}xml文件保存public void SaveXmlDoc(){//获取根节点对象XDocument document new XDocument();XElement xmlRoot new XElement(MemorandumModels);XElement memorandumModel;foreach (var memorandumReal in MemorandumRealList){memorandumModel new XElement($MemorandumModel);memorandumModel.SetElementValue(Title, memorandumReal.Title);memorandumModel.SetElementValue(EvenType, memorandumReal.EvenType);memorandumModel.SetElementValue(DateTime, memorandumReal.DateTime);memorandumModel.SetElementValue(IsComplete, memorandumReal.IsComplete);xmlRoot.Add(memorandumModel);}xmlRoot.Save(XmlDocPath);}④查询如果全选选中则显示全部内容未勾选则采用link去匹配选中信息去筛选我这里是所有信息去匹配的你也可以自己修改下去只匹配某一项或几项内容public void SearchClick(){SaveXmlDoc();if (SelectAll){MemorandumShowList new ObservableCollectionMemorandumModel(MemorandumRealList);return;}MemorandumShowList new ObservableCollectionMemorandumModel(MemorandumRealList.Where(t t.EvenType EvenTypeList[SelectedIndex]).Where(s s.IsComplete IsCompleteStatus).Where(p p.Title TitleText).Where(x x.DateTime DateTime.Parse(DataTimeContext)) .ToList() );}⑤标题栏未输入内容时显示灰色提示字体有输入时输入内容显示黑色字体这里采用事件处理获取到光标时public void LostFocus(){if (string.IsNullOrEmpty(TitleText)){TitleText 备忘录标题;TitleColor Color.DimGray;}}光标离开时public void GotFocus(){TitleText ;TitleColor Color.Black;}⑥选中行删除public void DeleteClick(){MemorandumRealList.Remove(SelectedItem);MemorandumShowList.Remove(SelectedItem);}⑦行号获取在行选择改变事件中去做public void GridControl_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e){GridControl gd sender as GridControl;SelectRow gd.GetSelectedRowHandles()[0];//选中行的行号}⑧添加信息public void Add(){MemorandumRealList.Add(new MemorandumModel(){Title titleText,DateTime DateTime.Parse(DataTimeContext),EvenType EvenTypeList[SelectedIndex],IsComplete IsCompleteStatus});MemorandumShowList.Add(new MemorandumModel(){Title titleText,DateTime DateTime.Parse(DataTimeContext),EvenType EvenTypeList[SelectedIndex],IsComplete IsCompleteStatus});}⑨修改信息public void Modify(){MemorandumRealList[SelectRow] new MemorandumModel(){Title titleText,DateTime DateTime.Parse(DataTimeContext),EvenType EvenTypeList[SelectedIndex],IsComplete IsCompleteStatus};MemorandumShowList[SelectRow] new MemorandumModel(){Title titleText,DateTime DateTime.Parse(DataTimeContext),EvenType EvenTypeList[SelectedIndex],IsComplete IsCompleteStatus};}⑩定时器查询采用using System.Threading.Tasks;下的单线程定时器DispatcherTimer定义和初始化private DispatcherTimer timer;timer new DispatcherTimer();timer.Interval TimeSpan.FromMinutes(1);timer.Tick timer1_Tick;timer.Start();定时器事件我这里每隔一分钟查询一次查询到当前事件到了提醒时间就进行一次语音播报private void timer1_Tick(object sender, EventArgs e){foreach (var memorandum in MemorandumRealList){if(DateTime.Now memorandum.DateTime){SpeakAsync(memorandum.Title);}}}⑩①语音播报这里开了task线程执行/// summary/// 微软语音识别/// /summary/// param namecontent提示内容/parampublic static void SpeakAsync(string content){try{Task.Run(() {SpVoice voice new SpVoice();voice.Rate 1;//速率[-10,10]voice.Volume 10;//音量[0,100]voice.Voice voice.GetVoices().Item(0);//语音库voice.Speak(content);});}catch (Exception ex){throw ex;}}⑩② 界面时间处理界面的表格采用的dev控件gridcontrol默认情况下时间只显示年月日如果需要显示时分需要设定EditSettings如下dxg:GridColumn Header提醒时间 FieldNameDateTime MinWidth120 dxg:GridColumn.EditSettings!--xctk:DateEditSettings DisplayFormatdd-MM-yyyy HH:mm:ss.fff/--xctk:DateEditSettings DisplayFormatyyyy-MM-dd HH:mm//dxg:GridColumn.EditSettings/dxg:GridColumn如果使用的是wpf 自带的表格控件datagrid相对好处理DataGridTextColumn Header提醒时间 Binding{Binding PathDateTime,StringFormatyyyy年MM月dd日 HH:mm:ss} MinWidth300 /界面顶端的时间控件采用toolkit下的xctk1:DateTimeUpDown这个控件她绑定的是一个字符串类型的数据所以添加时候需要将他转换为datetime类型 DateTime.Parse(DataTimeContext)或者 DateTime Convert.ToDateTime(DataTimeContext)xctk1:DateTimeUpDown x:Name_minimum FormatCustom FormatStringyyyy/MM/dd HH:mm Text{Binding DataTimeContext} HorizontalAlignmentLeft VerticalAlignmentCenterValue2016/01/01T12:00 Margin15,5/⑩③combobox枚举内容绑定public ObservableCollectionEvenType EvenTypeList { get; set; } new ObservableCollectionEvenType();foreach (EvenType evenType in Enum.GetValues(typeof(EvenType))){EvenTypeList.Add(evenType);}⑩④关于gridcontrol TableView 的常用属性介绍TableView 的常用属性AllowPerPixelScrolling //逐像素滚动
AllowScrollAnimation //滚动动画当下拉滚动条时有动画效果
NavigationStyle //选中方式是一行还是单元格
ShowIndicator //是否在每一行之前显示小方块
UseEvenRowBackground //隔行其背景颜色会有所区分
AllowScrollToFocusedRow //允许滚动到选中行
AllowResizing //允许调整尺寸
AllowSorting //允许排序
AutoWidth //允许自动调整列宽
AllowMoveColumnToDropArea //允许将一列拖到空白处进行分组
AllowGrouping //允许分组
AllowFilterEditor //允许显示过滤盘
AllowEditing //允许编辑
ShowGroupPanel//显示分组panel
ShowHorizontalLines ShowVerticalLines //显示表格中每行每列垂直和水平线
IsColumnMenuEnabled //是否关闭右键列菜单03—前台代码直接上代码比较简单不展开讲解了UserControlxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:localclr-namespace:Caliburn.Micro.Helloxmlns:calhttp://www.caliburnproject.org xmlns:sysclr-namespace:System;assemblymscorlibxmlns:dxghttp://schemas.devexpress.com/winfx/2008/xaml/grid xmlns:xctkhttp://schemas.devexpress.com/winfx/2008/xaml/editors xmlns:xctk1http://schemas.xceed.com/wpf/xaml/toolkit x:ClassCaliburn.Micro.Hello.MemorandumView mc:Ignorabled d:DesignHeight450 d:DesignWidth800 UserControl.Resourceslocal:FontColorConverter x:KeyFontColorConverter /Style TargetType{x:Type TextBox}Setter PropertyHorizontalContentAlignment ValueLeft/Setter PropertyVerticalContentAlignment ValueCenter/Setter PropertyWidth Value100/
/StyleStyle TargetType{x:Type CheckBox}Setter PropertyHorizontalAlignment ValueCenter/Setter PropertyVerticalAlignment ValueCenter/Setter PropertyForeground ValueBlack/
/StyleStyle TargetTypeButtonSetter PropertyForeground ValueBlack/
/StyleDataTemplate x:KeyrowIndicatorContentTemplateStackPanel VerticalAlignmentStretchHorizontalAlignmentStretchTextBlock Text{Binding RowHandle.Value}TextAlignmentCenter ForegroundBlack//StackPanel/DataTemplate/UserControl.ResourcesStackPanel OrientationVerticalStackPanel OrientationHorizontalTextBox Text{Binding TitleText} Margin15,5 cal:Message.Attach[Event GotFocus] [Action GotFocus];[Event LostFocus] [Action LostFocus] Foreground{Binding TitleColor, Converter{StaticResource FontColorConverter}}/ComboBox ItemsSource{Binding EvenTypeList} Margin15,5 SelectedIndex{Binding SelectedIndex} MinWidth100 ForegroundBlack/!--DatePicker Text{Binding DataTimeContext,ModeTwoWay,UpdateSourceTriggerPropertyChanged}SelectedDate{x:Static sys:DateTime.Now} HorizontalAlignmentLeft VerticalAlignmentCenter Margin15,5 /--xctk1:DateTimeUpDown x:Name_minimum FormatCustom FormatStringyyyy/MM/dd HH:mm Text{Binding DataTimeContext} HorizontalAlignmentLeft VerticalAlignmentCenterValue2016/01/01T12:00 Margin15,5/CheckBox IsChecked{Binding IsCompleteStatus} Margin15,5 Content是否完成 ForegroundBlack/Button Margin15,5 MinWidth60 cal:Message.Attach[Event Click] [Action SearchClick] WrapPanel Image Source/Images/search.png Width15 Height15 /TextBlock Text查找 VerticalAlignmentCenter //WrapPanel/Button/StackPanelBorder BorderBrushLightBlue CornerRadius2 BorderThickness2 dxg:GridControl AutoGenerateColumnsAddNew EnableSmartColumnsGenerationTrue AllowLiveDataShapingTrue cal:Message.Attach[Event SelectedItemChanged] [Action GridControl_SelectedItemChanged($source,$event)]; ItemsSource{Binding MemorandumShowList} SelectedItem{Binding SelectedItem} Height330 ForegroundBlackdxg:GridControl.Viewdxg:TableView ShowTotalSummaryTrue AllowMoveColumnToDropAreaFalse AllowGroupingFalse AutoExpandOnDragFalse ShowDragDropHintFalse ShowGroupPanelFalse AllowColumnMovingFalse AllowResizingFalse ForegroundBlackRowIndicatorContentTemplate{StaticResource rowIndicatorContentTemplate} //dxg:GridControl.Viewdxg:GridColumn Header标题 FieldNameTitle MinWidth100/dxg:GridColumn Header类型 FieldNameEvenType MinWidth100/dxg:GridColumn Header提醒时间 FieldNameDateTime MinWidth120 dxg:GridColumn.EditSettings!--xctk:DateEditSettings DisplayFormatdd-MM-yyyy HH:mm:ss.fff/--xctk:DateEditSettings DisplayFormatyyyy-MM-dd HH:mm//dxg:GridColumn.EditSettings/dxg:GridColumndxg:GridColumn Header状态 FieldNameIsComplete MinWidth100//dxg:GridControl/BorderStackPanel OrientationHorizontalCheckBox IsChecked{Binding SelectAll} Margin35,5 Content全选/Button Margin35,5 MinWidth60 cal:Message.Attach[Event Click] [Action DeleteClick] WrapPanel Image Source/Images/delete.png Width15 Height15 /TextBlock Text删除 VerticalAlignmentCenter //WrapPanel/ButtonButton Margin35,5 MinWidth60 NameAddWrapPanel Image Source/Images/add.png Width15 Height15 /TextBlock Text添加 VerticalAlignmentCenter //WrapPanel/ButtonButton Margin35,5 MinWidth60 NameModifyWrapPanel Image Source/Images/modify.png Width15 Height15/TextBlock Text修改 VerticalAlignmentCenter //WrapPanel/Button/StackPanel/StackPanel
/UserControl04—效果演示05—源码源码下载 链接https://pan.baidu.com/s/1yExT_zXFfd6TiAJYoD8kIw 提取码在下面这个公众号对话框发送【备忘录】或者直接添加小编微信mm1552923 获取。技术群添加小编微信并备注进群小编微信mm1552923 公众号dotNet编程大全