设计企业网站,实时积分榜,网站开发即时聊天源码,公司网站建设岗位备忘录功能页面完善以及优化 备忘录功能基本跟前一章节的待办事项差不多一至#xff0c;就不再做过多的笔述了 一.备忘录功能完整页面源码
MemoView.xaml
UserControl x:ClassMyToDo.Views.MemoViewxmlnshttp://schemas.microsoft.com/winfx/2006/xam…备忘录功能页面完善以及优化 备忘录功能基本跟前一章节的待办事项差不多一至就不再做过多的笔述了 一.备忘录功能完整页面源码
MemoView.xaml
UserControl x:ClassMyToDo.Views.MemoViewxmlnshttp://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:MyToDo.Viewsmc:Ignorabled xmlns:mdhttp://materialdesigninxaml.net/winfx/xaml/themesxmlns:cvclr-namespace:MyToDo.Common.Convertersxmlns:ihttp://schemas.microsoft.com/xaml/behaviorsd:DesignHeight450 d:DesignWidth800UserControl.Resourcescv:IntToVisibilityConveter x:KeyIntToVisibility//UserControl.Resourcesmd:DialogHostmd:DrawerHost IsRightDrawerOpen{Binding IsRightDrawerOpen}!--设计右边弹出层--md:DrawerHost.RightDrawerContent!--定义弹出层的内容区域--DockPanel Width300 LastChildFillFalseTextBox Text{Binding CurrentDto.Title} md:HintAssist.Hint请输入备忘录概要 Margin20,0 DockPanel.DockTop/TextBox Text{Binding CurrentDto.Content} md:HintAssist.Hint请输入备忘录内容 Margin20 MinHeight100 DockPanel.DockTop/Button Command{Binding ExecuteCommand} CommandParameter保存 Content添加到备忘录 DockPanel.DockTop Margin20,0 //DockPanel/md:DrawerHost.RightDrawerContentGridGrid.RowDefinitionsRowDefinition Heightauto/RowDefinition//Grid.RowDefinitionsStackPanel Margin15,0,0,0 OrientationHorizontal!--设置绑定模式和更新数据源类型--TextBox Text{Binding Search,ModeTwoWay,UpdateSourceTriggerPropertyChanged} Width250 VerticalAlignmentCenter md:HintAssist.Hint查找备忘录... md:TextFieldAssist.HasClearButtonTrue!--搜索框绑定回车事件--TextBox.InputBindings!--通过Key 绑定--KeyBinding KeyEnter Command{Binding ExecuteCommand} CommandParameter查询//TextBox.InputBindings/TextBox/StackPanelButton HorizontalAlignmentRight Content 添加备记录 Margin10,5 Command{Binding ExecuteCommand} CommandParameter新增 /!--当查不到数据时要显示的图片。添加转换器来控制要不要显示这个图片--StackPanel Grid.Row1 VerticalAlignmentCenter Visibility{Binding MemoDtos.Count,Converter{StaticResource IntToVisibility}}Image Source/Images/NoData.png Width620 Height220/TextBlock Margin0,10 FontSize18 HorizontalAlignmentCenter Text哇哦暂无数据//StackPanelScrollViewer Grid.Row1 ItemsControl HorizontalAlignmentCenter ItemsSource{Binding MemoDtos}ItemsControl.ItemsPanelItemsPanelTemplateWrapPanel //ItemsPanelTemplate/ItemsControl.ItemsPanel!--自定义内容模板--ItemsControl.ItemTemplateDataTemplatemd:TransitioningContent OpeningEffect{md:TransitionEffect KindExpandIn}!--自定义内容区域--Grid Width220 MinHeight180 MaxHeight250 Margin8 !--行为触发器--i:Interaction.Triggers!--鼠标左击事件--i:EventTrigger EventNameMouseLeftButtonUp!--设置命令--i:InvokeCommandAction CommandParameter{Binding}Command{Binding DataContext.SelectedCommand ,RelativeSource{RelativeSource ModeFindAncestor,AncestorTypeItemsControl}}//i:EventTrigger/i:Interaction.Triggers!--定义2行--Grid.RowDefinitionsRowDefinition Heightauto/RowDefinition //Grid.RowDefinitions!--右上角按钮--md:PopupBox HorizontalAlignmentRight Panel.ZIndex1Button Content删除 CommandParameter{Binding}Command{Binding DataContext.DeleteCommand ,RelativeSource{RelativeSource ModeFindAncestor,AncestorTypeItemsControl}}//md:PopupBox!--整个框圆角--Border CornerRadius3 Grid.RowSpan2 Background#3CB371/TextBlock Text{Binding Title} Padding10,5 FontWeightBold/TextBlock Text{Binding Content} Padding10,5 Grid.Row1/!--白色背景底色控件--Canvas Grid.RowSpan2 ClipToBoundsTrueBorder Canvas.Top10 CornerRadius100 Canvas.Right-50 Width120 Height120 Background#ffffff Opacity0.1/Border Canvas.Top80 CornerRadius100 Canvas.Right-30 Width120 Height120 Background#ffffff Opacity0.1//Canvas/Grid/md:TransitioningContent/DataTemplate/ItemsControl.ItemTemplate/ItemsControl/ScrollViewer/Grid/md:DrawerHost/md:DialogHost
/UserControlMemoViewModel.cs
namespace MyToDo.ViewModels
{public class MemoViewModel : NavigationViewModel{public MemoViewModel(IMemoService memoService, IContainerProvider provider) : base(provider){MemoDtos new ObservableCollectionMemoDto();ExecuteCommand new DelegateCommandstring(Execute);SelectedCommand new DelegateCommandMemoDto(Selected);DeleteCommand new DelegateCommandMemoDto(Delete);this.memoService memoService;}private bool isRightDrawerOpen;/// summary/// 右侧编辑窗口是否展开/// /summarypublic bool IsRightDrawerOpen{get { return isRightDrawerOpen; }set { isRightDrawerOpen value; RaisePropertyChanged(); }}private MemoDto currentDto;/// summary/// 编辑选中/新增对象/// /summarypublic MemoDto CurrentDto{get { return currentDto; }set { currentDto value; RaisePropertyChanged(); }}private string search;/// summary/// 用户输入的搜索条件/// /summarypublic string Search{get { return search; }set { search value; RaisePropertyChanged(); }}public DelegateCommandstring ExecuteCommand { get; private set; }public DelegateCommandMemoDto SelectedCommand { get; private set; }public DelegateCommandMemoDto DeleteCommand { get; private set; }private ObservableCollectionMemoDto memoDtos;private readonly IMemoService memoService;/// summary/// 创建数据的动态集合/// /summarypublic ObservableCollectionMemoDto MemoDtos{get { return memoDtos; }set { memoDtos value; RaisePropertyChanged(); }}async void GetDataAsync(){UpdateLoading(true); //发布消息设置加载中的窗口var memoResult await memoService.GetAllAsync(new Shared.Parameters.QueryParameter(){PageIndex 0,PageSize 100,Search Search});if (memoResult.Status){memoDtos.Clear();foreach (var item in memoResult.Result.Items){memoDtos.Add(item);}}UpdateLoading(false); //发布消息关闭加载中的窗口//for (int i 0; i 20; i)//{// memoDtos.Add(new MemoDto()// {// Title 标题 i,// Content 测试数据...// });//}}/// summary/// 添加备忘录/// /summary/// exception crefNotImplementedException/exceptionprivate void Add(){CurrentDto new MemoDto();//添加时初始化一个新对象IsRightDrawerOpen true;}private async void Save(){//判断数据是否为空if (string.IsNullOrWhiteSpace(CurrentDto.Title) || string.IsNullOrWhiteSpace(CurrentDto.Content)) return;UpdateLoading(true);try{if (CurrentDto.Id 0) //Id 大于0表示编辑。否则新增{var updateResult await memoService.UpdateAsync(CurrentDto);if (updateResult.Status) //更新成功{//查找到当前界面更新的那个条数据把显示的内容进行更新var todo memoDtos.FirstOrDefault(t t.Id CurrentDto.Id);if (todo ! null){todo.Title CurrentDto.Title;todo.Content CurrentDto.Content;}IsRightDrawerOpen false; //关闭编辑窗口}}else{var addResult await memoService.AddAsync(CurrentDto);if (addResult.Status){if (addResult.Result ! null){memoDtos.Add(addResult.Result); //把数据添加到界面的集合中IsRightDrawerOpen false; //关闭新增窗口}}}}catch (Exception ex){await Console.Out.WriteLineAsync(ex.Message);}finally{UpdateLoading(false);}}private async void Delete(MemoDto dto){try{UpdateLoading(true); //发布消息设置加载中的窗口var deleteResult await memoService.DeleteAsync(dto.Id);if (deleteResult.Status){//在当前数据集合中找到当前已经删除掉的数据并移除掉var model memoDtos.FirstOrDefault(t t.Id.Equals(dto.Id));if (model ! null) memoDtos.Remove(model);}}catch (Exception ex){await Console.Out.WriteLineAsync(ex.Message);}finally{UpdateLoading(false); //发布消息关闭加载中的窗口}}/// summary/// 根据不同的参数处理不同的逻辑/// /summary/// param nameobj/paramprivate void Execute(string obj){switch (obj){case 新增:Add();break;case 查询:GetDataAsync();break;case 保存:Save();break;}}private async void Selected(MemoDto obj){try{UpdateLoading(true);//进行数据查询var todoResult await memoService.GetFirstOfDefaultAsync(obj.Id);if (todoResult.Status){//把拿到的结果赋给一个当前选中的ToDoDtoCurrentDto todoResult.Result;IsRightDrawerOpen true;//打开窗口}}catch (Exception ex){await Console.Out.WriteLineAsync(ex.Message);}finally{UpdateLoading(false);}}//重写导航加载数据的方法public override void OnNavigatedTo(NavigationContext navigationContext){base.OnNavigatedTo(navigationContext);GetDataAsync();}}
}
二.错误排查
如果有出现相关的错误例如查询异常或其他其他。直接参考上一章节的错误排查就好了。