长沙网站运营,网站建设 APP开发销售怎么做,网站建设推广语,王烨甘肃文章目录 备忘录添加功能memoviewmodel.csmemo.view修改控制器 备忘录添加功能
由于todoview 和 memoview的相似度很高#xff0c;可复制todoview 的代码。
memoviewmodel.cs
using Mytodo.Common.Models;
using Mytodo.Service;
using Prism.Commands;
using Prism.Ioc;
u… 文章目录 备忘录添加功能memoviewmodel.csmemo.view修改控制器 备忘录添加功能
由于todoview 和 memoview的相似度很高可复制todoview 的代码。
memoviewmodel.cs
using Mytodo.Common.Models;
using Mytodo.Service;
using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using MyToDo.Share.Models;
using System.Threading.Tasks;
using Prism.Regions;
using System.Windows;namespace Mytodo.ViewModels
{public class MemoViewModel : NavigationViewModel{#region 命令定义/// summary/// 展开侧边栏/// /summarypublic DelegateCommand OpenRightContentCmd { set; get; }/// summary/// 打开选择的项/// /summarypublic DelegateCommandMemoDto SelectedCommand { get; set; }/// summary/// 添加、编辑 项/// /summarypublic DelegateCommandstring ExecuteCommand { get; set; }/// summary/// 删除项/// /summarypublic DelegateCommandMemoDto DeleteCommand { get; set; }#endregion#region 属性定义/// summary/// 项目状态/// /summarypublic int SelectIndex{get { return selectIndex; }set { selectIndex value; RaisePropertyChanged(); }}/// summary/// 当前选中项/// /summarypublic MemoDto? CurrDto{get { return currDto; }set { currDto value; RaisePropertyChanged(); }}/// summary/// 指示侧边栏是否展开/// /summarypublic bool IsRightOpen{get { return isRightOpen; }set { isRightOpen value; RaisePropertyChanged(); }}/// summary/// todo集合/// /summarypublic ObservableCollectionMemoDto? MemoDtos{get { return memoDtos; }set { memoDtos value; RaisePropertyChanged(); }}/// summary/// 右侧侧边栏标题/// /summarypublic string RightContentTitle{get { return rightContentTitle; }set { rightContentTitle value; RaisePropertyChanged(); }}/// summary/// 要搜索的字符串/// /summarypublic string SearchString{get { return search; }set { search value; RaisePropertyChanged(); }}#endregion#region 重要字段定义private readonly IMemoService service;#endregion#region 字段定义private int selectIndex;private MemoDto currDto;private bool isRightOpen;private ObservableCollectionMemoDto? memoDtos;private string rightContentTitle;private string search;#endregion#region 命令方法/// summary/// 删除指定项/// /summary/// param namedto/paramasync private void DeleteItem(MemoDto dto){var delres await service.DeleteAsync(dto.Id);if (delres.Status){var model MemoDtos.FirstOrDefault(t t.Id.Equals(dto.Id));MemoDtos.Remove(dto);}}private void ExceuteCmd(string obj){switch (obj){case 添加:Add(); break;case 查询:Query(); break;case 保存:Save(); break;}}/// summary/// 保存消息/// /summaryprivate async void Save(){try{if (string.IsNullOrWhiteSpace(CurrDto.Title) || string.IsNullOrWhiteSpace(CurrDto.Content))return;UpdateLoding(true);if (CurrDto.Id 0) //编辑项{var updateres await service.UpdateAsync(CurrDto);if (updateres.Status){UpdateDataAsync();}else{MessageBox.Show(更新失败);}}else{//添加项var add_res await service.AddAsync(CurrDto);//刷新if (add_res.Status) //如果添加成功{MemoDtos.Add(add_res.Result);}else{MessageBox.Show(添加失败);}}}catch{}finally{IsRightOpen false;//卸载数据加载窗体UpdateLoding(false);}}/// summary/// 打开待办事项弹窗/// /summaryvoid Add(){CurrDto new MemoDto();IsRightOpen true;}private void Query(){GetDataAsync();}/// summary/// 根据条件更新数据/// /summaryasync void UpdateDataAsync(){var memoResult await service.GetAllAsync(new MyToDo.Share.Parameters.QueryParameter { PageIndex 0, PageSize 100, Search SearchString });if (memoResult.Status){MemoDtos.Clear();foreach (var item in memoResult.Result.Items)MemoDtos.Add(item);}}/// summary/// 获取所有数据/// /summaryasync void GetDataAsync(){//调用数据加载页面UpdateLoding(true);//更新数据UpdateDataAsync();//卸载数据加载页面UpdateLoding(false);}/// summary/// 弹出详细信息/// /summary/// param nameobj/paramprivate async void Selected(MemoDto obj){var todores await service.GetFirstOfDefaultAsync(obj.Id);if (todores.Status){CurrDto todores.Result;IsRightOpen true;RightContentTitle 我的待办;}}#endregionpublic MemoViewModel(IMemoService service, IContainerProvider provider) : base(provider){//初始化对象MemoDtos new ObservableCollectionMemoDto();RightContentTitle 添加备忘率;//初始化命令SelectedCommand new DelegateCommandMemoDto(Selected);OpenRightContentCmd new DelegateCommand(Add);ExecuteCommand new DelegateCommandstring(ExceuteCmd);DeleteCommand new DelegateCommandMemoDto(DeleteItem);this.service service;}public override void OnNavigatedTo(NavigationContext navigationContext){base.OnNavigatedTo(navigationContext);GetDataAsync();}}
}
memo.view
UserControlx:ClassMytodo.Views.MemoViewxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:cvclr-namespace:Mytodo.Common.Convertersxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:ihttp://schemas.microsoft.com/xaml/behaviorsxmlns:localclr-namespace:Mytodo.Viewsxmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:mdhttp://materialdesigninxaml.net/winfx/xaml/themesd:DesignHeight450d:DesignWidth800mc:IgnorabledUserControl.ResourcesResourceDictionarycv:IntToVisibilityConveter x:KeyIntToVisility //ResourceDictionary/UserControl.Resourcesmd:DialogHostmd:DrawerHost IsRightDrawerOpen{Binding IsRightOpen}md:DrawerHost.RightDrawerContentDockPanelMinWidth200MaxWidth240Margin2LastChildFillFalseTextBlockMargin10DockPanel.DockTopFontFamily微软雅黑FontSize20FontWeightBoldText{Binding RightContentTitle} /StackPanelMargin10DockPanel.DockTopOrientationHorizontalTextBlockMargin5VerticalAlignmentCenterFontFamily微软雅黑FontSize14Text状态 //StackPanelTextBoxMargin10md:HintAssist.Hint备忘录事项标题DockPanel.DockTopFontFamily微软雅黑FontSize12Text{Binding CurrDto.Title} /TextBoxMinHeight50Margin10md:HintAssist.Hint备忘录事项内容DockPanel.DockTopFontFamily微软雅黑FontSize12Text{Binding CurrDto.Content}TextWrappingWrap /ButtonMargin10,5HorizontalAlignmentCenterCommand{Binding ExecuteCommand}CommandParameter保存Content保存DockPanel.DockTop //DockPanel/md:DrawerHost.RightDrawerContentGridGrid.RowDefinitionsRowDefinition Heightauto /RowDefinition //Grid.RowDefinitionsStackPanel Margin15,10 OrientationHorizontalTextBoxWidth200md:HintAssist.Hint查找备忘录中md:TextFieldAssist.HasClearButtonTrueFontFamily微软雅黑FontSize14Text{Binding SearchString, ModeTwoWay, UpdateSourceTriggerPropertyChanged}TextBox.InputBindingsKeyBindingKeyEnterCommand{Binding ExecuteCommand}CommandParameter查询 //TextBox.InputBindings/TextBox/StackPanelButtonMargin10,0HorizontalAlignmentRightCommand{Binding OpenRightContentCmd}Content 添加到备忘FontFamily微软雅黑FontSize14 /StackPanelGrid.Row1VerticalAlignmentCenterVisibility{Binding MemoDtos.Count, Converter{StaticResource IntToVisility}}md:PackIconWidth120Height120HorizontalAlignmentCenterKindClipboardText /TextBlockMargin0,10HorizontalAlignmentCenterFontSize18Text尝试添加一些待办事项以便在此处查看它们。 //StackPanelItemsControlGrid.Row1Margin10ItemsSource{Binding MemoDtos}ItemsControl.ItemsPanelItemsPanelTemplateWrapPanel //ItemsPanelTemplate/ItemsControl.ItemsPanelItemsControl.ItemTemplateDataTemplateBorder MinWidth200 Margin10Grid MinHeight150i:Interaction.Triggersi:EventTrigger EventNameMouseLeftButtonUpi:InvokeCommandAction Command{Binding DataContext.SelectedCommand, RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeItemsControl}} CommandParameter{Binding} //i:EventTrigger/i:Interaction.TriggersGrid.RowDefinitionsRowDefinition Heightauto /RowDefinition //Grid.RowDefinitionsDockPanel Panel.ZIndex2 LastChildFillFalseTextBlockMargin10,10FontFamily黑体FontSize14Text{Binding Title} /md:PopupBoxMargin5Panel.ZIndex1DockPanel.DockRightButtonPanel.ZIndex2Command{Binding DataContext.DeleteCommand, RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeItemsControl}}CommandParameter{Binding}Content删除 //md:PopupBox/DockPanelTextBlockGrid.Row1Margin10,5FontFamily黑体FontSize12Opacity0.7Text{Binding Content} /Canvas Grid.RowSpan2 ClipToBoundsTrueBorderCanvas.Top10Canvas.Right-50Width120Height120Background#FFFFFFCornerRadius100Opacity0.1 /BorderCanvas.Top80Canvas.Right-30Width120Height120Background#FFFFFFCornerRadius100Opacity0.1 //CanvasBorderGrid.RowSpan2Background#ffffccCornerRadius5Opacity0.3 //Grid/Border/DataTemplate/ItemsControl.ItemTemplate/ItemsControl/Grid/md:DrawerHost/md:DialogHost
/UserControl
修改控制器
public async TaskApiReponse Delete(int todoid) await service.DeleteApublic async TaskApiReponse Delete(int todoid)