WPF实战学习笔记21-自定义首页添加对话服务

这篇具有很好参考价值的文章主要介绍了WPF实战学习笔记21-自定义首页添加对话服务。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

自定义首页添加对话服务

定义接口与实现

添加自定义添加对话框接口

添加文件:Mytodo.Dialog.IDialogHostAware.cs

using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Dialog
{
    public interface IDialogHostAware
    {
        /// <summary>
        /// DialoHost名称
        /// </summary>
        string DialogHostName { get; set; }

        /// <summary>
        /// 打开过程中执行
        /// </summary>
        /// <param name="parameters"></param>
        void OnDialogOpend(IDialogParameters parameters);

        /// <summary>
        /// 确定
        /// </summary>
        DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 取消
        /// </summary>
        DelegateCommand CancelCommand { get; set; }
    }
}

添加自定义添加对话框显示接口

注意dialogHostName应与view中dialoghost 的Identifier属性一致

using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Dialog
{
    public interface  IDialogHostService:IDialogService
    {
        /// <summary>
        /// 显示Dialog方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parameters"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        Task<IDialogResult> ShowDialog(string name, IDialogParameters parameters, string dialogHostName = "Root");
    }
}
实现IDialogHostService接口

添加文件:Mytodo.Dialog.DialogHostService.cs

DialogHostService实现了自定义的IDialogHostService接口,以及DialogService类.

DialogService:可参考https://www.cnblogs.com/chonglu/p/15159387.html

Prism提供了一组对话服务, 封装了常用的对话框组件的功能, 例如:

  • RegisterDialog/IDialogService (注册对话及使用对话)
  • 打开对话框传递参数/关闭对话框返回参数
  • 回调通知对话结果
using MaterialDesignThemes.Wpf;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Mytodo.Dialog
{
    public class DialogHostService:DialogService, IDialogHostService
    {
        private readonly IContainerExtension containerExtension;

        public DialogHostService(IContainerExtension containerExtension) : base(containerExtension)
        {
            this.containerExtension = containerExtension;
        }

        public async Task<IDialogResult> ShowDialog(string name, IDialogParameters parameters, string dialogHostName = "Root")
        {
            if (parameters == null)
                parameters = new DialogParameters();

            //从容器当中去除弹出窗口的实例
            var content = containerExtension.Resolve<object>(name);

            //验证实例的有效性 
            if (!(content is FrameworkElement dialogContent))
                throw new NullReferenceException("A dialog's content must be a FrameworkElement");

            if (dialogContent is FrameworkElement view && view.DataContext is null && ViewModelLocator.GetAutoWireViewModel(view) is null)
                ViewModelLocator.SetAutoWireViewModel(view, true);

            if (!(dialogContent.DataContext is IDialogHostAware viewModel))
                throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface");

            viewModel.DialogHostName = dialogHostName;

            DialogOpenedEventHandler eventHandler = (sender, eventArgs) =>
            {
                if (viewModel is IDialogHostAware aware)
                {
                    aware.OnDialogOpend(parameters);
                }
                eventArgs.Session.UpdateContent(content);
            };

            return (IDialogResult)await DialogHost.Show(dialogContent, viewModel.DialogHostName, eventHandler);
        }
    }
}

添加对应的窗体

添加AddMemoView

添加文件Mytodo.Views.Dialogs.AddMemoView.xaml

<UserControl
    x:Class="Mytodo.Views.Dialogs.AddMemoView"
    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:local="clr-namespace:Mytodo.Views"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <Grid Width="400">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>

        <TextBlock
            Padding="20,10"
            FontSize="20"
            FontWeight="Bold"
            Text="添加备忘录" />

        <DockPanel Grid.Row="1" LastChildFill="False">

            <TextBox
                Margin="20,0"
                md:HintAssist.Hint="请输入备忘录概要"
                DockPanel.Dock="Top"
                Text="{Binding Model.Title}" />

            <TextBox
                MinHeight="100"
                Margin="20,10"
                md:HintAssist.Hint="请输入备忘录内容"
                AcceptsReturn="True"
                DockPanel.Dock="Top"
                Text="{Binding Model.Content}"
                TextWrapping="Wrap" />
        </DockPanel>

        <StackPanel
            Grid.Row="2"
            Margin="10"
            HorizontalAlignment="Right"
            Orientation="Horizontal">
            <Button
                Margin="0,0,10,0"
                Command="{Binding CancelCommand}"
                Content="取消"
                Style="{StaticResource MaterialDesignOutlinedButton}" />
            <Button Command="{Binding SaveCommand}" Content="确定" />
        </StackPanel>
    </Grid>
</UserControl>

添加文件:Mytodo.Views.Dialogs.AddMemoViewmodel.cs

using MaterialDesignThemes.Wpf;
using Mytodo.Dialog;
using MyToDo.Share.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.ViewModels.Dialogs
{
    internal class AddMemoViewModel : BindableBase, IDialogHostAware
    {
        public AddMemoViewModel()
        {
            SaveCommand = new DelegateCommand(Save);
            CancelCommand = new DelegateCommand(Cancel);
        }

        private MemoDto model;

        public MemoDto Model
        {
            get { return model; }
            set { model = value; RaisePropertyChanged(); }
        }

        private void Cancel()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
        }

        private void Save()
        {
            if (string.IsNullOrWhiteSpace(Model.Title) ||
                string.IsNullOrWhiteSpace(model.Content)) return;

            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                //确定时,把编辑的实体返回并且返回OK
                DialogParameters param = new DialogParameters();
                param.Add("Value", Model);
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param));
            }
        }

        public string DialogHostName { get; set; }
        public DelegateCommand SaveCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }

        public void OnDialogOpend(IDialogParameters parameters)
        {
            if (parameters.ContainsKey("Value"))
            {
                Model = parameters.GetValue<MemoDto>("Value");
            }
            else
                Model = new MemoDto();
        }
    }
}

添加AddTodoView

添加文件Mytodo.Views.Dialogs.AddtodoView.xaml

<UserControl
    x:Class="Mytodo.Views.TodoView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cv="clr-namespace:Mytodo.Common.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:local="clr-namespace:Mytodo.Views"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <cv:IntToVisibilityConveter x:Key="IntToVisility" />
        </ResourceDictionary>
    </UserControl.Resources>
    <md:DialogHost>
        <md:DrawerHost IsRightDrawerOpen="{Binding IsRightOpen}">
            <md:DrawerHost.RightDrawerContent>
                <DockPanel
                    MinWidth="200"
                    MaxWidth="240"
                    Margin="2"
                    LastChildFill="False">
                    <TextBlock
                        Margin="10"
                        DockPanel.Dock="Top"
                        FontFamily="微软雅黑"
                        FontSize="20"
                        FontWeight="Bold"
                        Text="{Binding RightContentTitle}" />
                    <StackPanel
                        Margin="10"
                        DockPanel.Dock="Top"
                        Orientation="Horizontal">
                        <TextBlock
                            Margin="5"
                            VerticalAlignment="Center"
                            FontFamily="微软雅黑"
                            FontSize="14"
                            Text="状态" />
                        <ComboBox Margin="5" SelectedIndex="{Binding CurrDto.Status}">
                            <ComboBoxItem Content="已完成" FontSize="12" />
                            <ComboBoxItem Content="未完成" FontSize="12" />
                        </ComboBox>
                    </StackPanel>
                    <TextBox
                        Margin="10"
                        md:HintAssist.Hint="待办事项标题"
                        DockPanel.Dock="Top"
                        FontFamily="微软雅黑"
                        FontSize="12"
                        Text="{Binding CurrDto.Title}" />
                    <TextBox
                        MinHeight="50"
                        Margin="10"
                        md:HintAssist.Hint="待办事项内容"
                        DockPanel.Dock="Top"
                        FontFamily="微软雅黑"
                        FontSize="12"
                        Text="{Binding CurrDto.Content}"
                        TextWrapping="Wrap" />
                    <Button
                        Margin="10,5"
                        HorizontalAlignment="Center"
                        Command="{Binding ExecuteCommand}"
                        CommandParameter="保存"
                        Content="保存"
                        DockPanel.Dock="Top" />
                </DockPanel>
            </md:DrawerHost.RightDrawerContent>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <StackPanel Margin="15,10" Orientation="Horizontal">
                    <TextBox
                        Width="200"
                        md:HintAssist.Hint="查找待办事项"
                        md:TextFieldAssist.HasClearButton="True"
                        FontFamily="微软雅黑"
                        FontSize="14"
                        Text="{Binding SearchString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                        <TextBox.InputBindings>
                            <KeyBinding
                                Key="Enter"
                                Command="{Binding ExecuteCommand}"
                                CommandParameter="查询" />
                        </TextBox.InputBindings>
                    </TextBox>
                    <TextBlock
                        Margin="10"
                        FontSize="14"
                        Text="筛选" />
                    <ComboBox
                        Width="auto"
                        MinWidth="30"
                        FontFamily="微软雅黑"
                        FontSize="14"
                        SelectedIndex="{Binding SelectIndex}">
                        <ComboBoxItem Content="全部" />
                        <ComboBoxItem Content="已完成" />
                        <ComboBoxItem Content="未完成" />
                    </ComboBox>
                </StackPanel>
                <Button
                    Margin="10,0"
                    HorizontalAlignment="Right"
                    Command="{Binding ExecuteCommand}"
                    CommandParameter="添加"
                    Content="+ 添加到待办"
                    FontFamily="微软雅黑"
                    FontSize="14" />
                <StackPanel
                    Grid.Row="1"
                    VerticalAlignment="Center"
                    Visibility="{Binding TodoDtos.Count, Converter={StaticResource IntToVisility}}">
                    <md:PackIcon
                        Width="120"
                        Height="120"
                        HorizontalAlignment="Center"
                        Kind="ClipboardText" />
                    <TextBlock
                        Margin="0,10"
                        HorizontalAlignment="Center"
                        FontSize="18"
                        Text="尝试添加一些待办事项,以便在此处查看它们。" />
                </StackPanel>
                <ItemsControl
                    Grid.Row="1"
                    Margin="10"
                    ItemsSource="{Binding TodoDtos}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Border MinWidth="200" Margin="10">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Status}" Value="0">
                                                <Setter Property="Background" Value="#1E90FF" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Status}" Value="1">
                                                <Setter Property="Background" Value="#3CB371" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                                <Grid MinHeight="150">
                                    <!--  给项目添加行为  -->
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="MouseLeftButtonUp">
                                            <i:InvokeCommandAction Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <DockPanel Panel.ZIndex="2" LastChildFill="False">
                                        <TextBlock
                                            Margin="10,10"
                                            FontFamily="黑体"
                                            FontSize="14"
                                            Text="{Binding Title}" />
                                        <!--<md:PackIcon
                                            Margin="10,10"
                                            VerticalContentAlignment="Top"
                                            DockPanel.Dock="Right"
                                            Kind="More" />-->
                                        <md:PopupBox
                                            Margin="5"
                                            Panel.ZIndex="1"
                                            DockPanel.Dock="Right">
                                            <Button
                                                Panel.ZIndex="2"
                                                Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
                                                CommandParameter="{Binding}"
                                                Content="删除" />
                                        </md:PopupBox>
                                    </DockPanel>
                                    <TextBlock
                                        Grid.Row="1"
                                        Margin="10,5"
                                        FontFamily="黑体"
                                        FontSize="12"
                                        Opacity="0.7"
                                        Text="{Binding Content}" />
                                    <Canvas Grid.RowSpan="2" ClipToBounds="True">
                                        <Border
                                            Canvas.Top="10"
                                            Canvas.Right="-50"
                                            Width="120"
                                            Height="120"
                                            Background="#FFFFFF"
                                            CornerRadius="100"
                                            Opacity="0.1" />
                                        <Border
                                            Canvas.Top="80"
                                            Canvas.Right="-30"
                                            Width="120"
                                            Height="120"
                                            Background="#FFFFFF"
                                            CornerRadius="100"
                                            Opacity="0.1" />
                                    </Canvas>
                                    <Border
                                        Grid.RowSpan="2"
                                        Background="#ffcccc"
                                        CornerRadius="5"
                                        Opacity="0.3" />
                                </Grid>

                            </Border>

                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </md:DrawerHost>
    </md:DialogHost>
</UserControl>

添加文件:Mytodo.Views.Dialogs.AddTodoViewmodel.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 TodoViewModel: NavigationViewModel
    {
        #region 命令定义

        /// <summary>
        /// 展开侧边栏
        /// </summary>
        public DelegateCommand OpenRightContentCmd { set; get; }

        /// <summary>
        /// 打开选择的项
        /// </summary>
        public DelegateCommand<ToDoDto> SelectedCommand { get; set; }

        /// <summary>
        /// 添加、编辑 项
        /// </summary>
        public DelegateCommand<string> ExecuteCommand { get; set; }

        /// <summary>
        /// 删除项
        /// </summary>
        public DelegateCommand<ToDoDto> DeleteCommand { get; set; }

        #endregion

        #region 属性定义


        /// <summary>
        /// 项目状态
        /// </summary>
        public int SelectIndex
        {
            get { return selectIndex; }
            set { selectIndex = value; RaisePropertyChanged(); }
        }


        /// <summary>
        /// 当前选中项
        /// </summary>
        public ToDoDto? CurrDto
        {
            get { return currDto; }
            set { currDto = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 指示侧边栏是否展开
        /// </summary>
        public bool IsRightOpen
        {
            get { return isRightOpen; }
            set { isRightOpen = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// todo集合
        /// </summary>
        public ObservableCollection<ToDoDto>? TodoDtos
        {
            get { return todoDtos; }
            set { todoDtos = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 右侧侧边栏标题
        /// </summary>
        public string RightContentTitle
        {
            get { return rightContentTitle; }
            set { rightContentTitle = value;RaisePropertyChanged(); }
        }

        /// <summary>
        /// 要搜索的字符串
        /// </summary>
        public string SearchString
        {
            get { return search; }
            set { search = value; RaisePropertyChanged(); }
        }

        #endregion

        #region 重要字段定义

        private readonly ITodoService service;

        #endregion

        #region 字段定义
        private int selectIndex;
        private ToDoDto currDto;
        private bool isRightOpen;
        private ObservableCollection<ToDoDto>? todoDtos;
        private string rightContentTitle;
        private string search;



        #endregion

        #region 命令方法


        /// <summary>
        /// 删除指定项
        /// </summary>
        /// <param name="dto"></param>
        async private void DeleteItem(ToDoDto dto)
        {
            var delres = await service.DeleteAsync(dto.Id);

            if (delres.Status)
            {
                var model = TodoDtos.FirstOrDefault(t => t.Id.Equals(dto.Id));
                TodoDtos.Remove(dto);
            }
        }


        private void ExceuteCmd(string obj)
        {
            switch (obj)
            {
                case "添加":
                    Add(); break;
                case "查询":
                    Query();break;
                case "保存":
                    Save(); break;
            }
        }


        /// <summary>
        /// 保存消息
        /// </summary>
        private 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) //如果添加成功
                    {
                        TodoDtos.Add(add_res.Result);
                    }
                    else
                    {
                        MessageBox.Show("添加失败");

                    }
                       
                }
            }
            catch
            {

            }
            finally
            {
                IsRightOpen = false;
                //卸载数据加载窗体
                UpdateLoding(false);
            }
        }


        /// <summary>
        /// 打开待办事项弹窗
        /// </summary>
        void Add()
        {
            CurrDto = new ToDoDto();
            IsRightOpen = true;
        }

        private void Query()
        {
            GetDataAsync();
        }



        /// <summary>
        /// 根据条件更新数据
        /// </summary>
        async void UpdateDataAsync()
        {
            int? Status = SelectIndex == 0 ? null : SelectIndex == 2 ? 1 : 0;


            var todoResult = await service.GetAllFilterAsync(new MyToDo.Share.Parameters.TodoParameter { PageIndex = 0, PageSize = 100, Search = SearchString, Status = Status });

            if (todoResult.Status)
            {
                todoDtos.Clear();
                foreach (var item in todoResult.Result.Items)
                    todoDtos.Add(item);
            }
        }



        /// <summary>
        /// 获取所有数据
        /// </summary>
        async void GetDataAsync()
        {
            //调用数据加载页面
            UpdateLoding(true);

            //更新数据
            UpdateDataAsync();

            //卸载数据加载页面
            UpdateLoding(false);
        }


        /// <summary>
        /// 弹出详细信息
        /// </summary>
        /// <param name="obj"></param>
        private async void Selected(ToDoDto obj)
        {
            var todores = await service.GetFirstOfDefaultAsync(obj.Id);
            if(todores.Status)
            {
                CurrDto = todores.Result;
                IsRightOpen = true;
                RightContentTitle = "我的待办";
            }
        }

        #endregion

        public TodoViewModel(ITodoService service,IContainerProvider provider) : base(provider)
        {
            //初始化对象
            TodoDtos = new ObservableCollection<ToDoDto>();  
            RightContentTitle = "添加血雨待办";

            //初始化命令
            SelectedCommand         = new DelegateCommand<ToDoDto>(Selected);
            OpenRightContentCmd     = new DelegateCommand(Add);
            ExecuteCommand          = new DelegateCommand<string>(ExceuteCmd);
            DeleteCommand           = new DelegateCommand<ToDoDto>(DeleteItem);

            this.service = service;
        }



        public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            base.OnNavigatedTo(navigationContext);

            GetDataAsync();
        }

    }
}

修改绑定

修改文件:"Mytodo.Views.IndexView.xaml

Background="{Binding Color}"
CornerRadius="5"
Opacity="0.9">
<Border.Style>

    <Button
            Width="30"
            Height="30"
            Margin="10"
            VerticalAlignment="Top"
            Command="{Binding ExecuteCommand}"
            CommandParameter="新增待办"
            Content="{materialDesign:PackIcon Kind=Add}"
            DockPanel.Dock="Right"
            Style="{StaticResource MaterialDesignFloatingActionAccentButton}" />
    <Button
            Width="30"
            Height="30"
            Margin="10"
            VerticalAlignment="Top"
            Command="{Binding ExecuteCommand}"
            CommandParameter="新增备忘"
            Content="{materialDesign:PackIcon Kind=Add}"
            DockPanel.Dock="Right"
            Style="{StaticResource MaterialDesignFloatingActionAccentButton}" />

依赖注入

修改文件:Mytodo.App.xmal.cs文章来源地址https://www.toymoban.com/news/detail-617768.html

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{

    //注册服务
    containerRegistry.GetContainer().Register<HttpRestClient>(made: Parameters.Of.Type<string>(serviceKey: "webUrl"));
    containerRegistry.GetContainer().RegisterInstance(@"Http://localhost:19007/", serviceKey: "webUrl");

    containerRegistry.Register<ITodoService, TodoService>();
    containerRegistry.Register<IMemoService, MemoService>();
    containerRegistry.Register<IDialogHostService, DialogHostService>();

    //注册对话框
    containerRegistry.RegisterForNavigation<AddTodoView,AddTodoViewModel>();
    containerRegistry.RegisterForNavigation<AddMemoView,AddMemoViewModel>();


    containerRegistry.RegisterForNavigation<AboutView, AboutViewModel>();
    containerRegistry.RegisterForNavigation<SysSetView, SysSetViewModel>();
    containerRegistry.RegisterForNavigation<SkinView, SkinViewModel>();
    containerRegistry.RegisterForNavigation<IndexView, IndexViewModel>();
    containerRegistry.RegisterForNavigation<TodoView, TodoViewModel>();
    containerRegistry.RegisterForNavigation<MemoView, MemoViewModel>();
    containerRegistry.RegisterForNavigation<SettingsView, SettingsViewModel>();
}

到了这里,关于WPF实战学习笔记21-自定义首页添加对话服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • WPF实战学习笔记26-首页导航

    修改UI,添加单击行为,并绑定导航命令 修改文件:Mytodo.Views.IndexView.xaml ,在导航梯形添加内容 添加导航命令,并初始化 修改文件:indexviewmodel.cs 添加导航区域变量,并初始化 修改文件:indexviewmodel.cs 添加导航方法 TaskBars添加对应的导航区域 修改OnNavigate方法 当为“已完成

    2024年02月15日
    浏览(33)
  • WPF实战学习笔记24-首页编辑与完成

    indexview添加Listbox控件的鼠标双击行为 添加todo、memo的编辑命令 indexviewmodel添加对应的更新事件处理 添加ToggleButton与后台的绑定 将ToggleButton的ischeck绑定到status属性 添加bool int 转换器 添加完成命令 添加完成功能函数 Listbox添加行为 给行为添加命令空间 文件:Mytodo.Views.IndexV

    2024年02月14日
    浏览(34)
  • WPF实战学习笔记19-备忘录添加功能

    由于todoview 和 memoview的相似度很高,可复制todoview 的代码。 memoviewmodel.cs memo.view 修改控制器

    2024年02月15日
    浏览(37)
  • WPF实战学习笔记17-TodoView 添加新增、编辑、查询功能

    修改TodoViewModel.cs 修改XAML 添加引用 添加绑定 添加项目的双击事件 修改ToDoService 修改MyToDo.Api/Service/ToDoService.cs

    2024年02月15日
    浏览(39)
  • WPF实战学习笔记29-登录数据绑定,编写登录服务

    添加登录绑定字段、命令、方法 修改对象:Mytodo.ViewModels.ViewModels 添加密码依赖对象行为 添加文件:Mytodo.Extensions.PassWordExtensions ### 登录UI添加密码行为 修改文件:Mytodo.Views.LoginView.xmal 添加命名空间,略 修改passbox。 添加加密方法,并使用 添加文件:MyToDo.Share.StringE

    2024年02月15日
    浏览(36)
  • qt学习:实战 笔记本 (对话框+文件)

    目录 第一步,配置ui界面  第二步,头文件  第三步,颜色对话框点击事件  第四步,字体对话框点击事件  第五步,输入对话框点击事件  第六步,打开文件对话框点击事件  第七步,另存为对话框点击事件

    2024年01月22日
    浏览(36)
  • WPF实战学习笔记27-全局通知

    新建消息事件 添加文件:Mytodo.Common.Events.MessageModel.cs 注册、发送提示消息 UI增加Snackbar 修改文件:Mytodo.Views.MainView.xaml 注册消息 修改文件:Mytodo.Views.MainViewcs 构造函数添加 要注意的是,我们要发送的是文本,所以,this.skbar.MessageQueue.Enqueue函数内发送的是文本。 在需要的地

    2024年02月15日
    浏览(38)
  • WPF实战学习笔记28-登录界面

    添加登录界面UI 添加文件loginview.xaml。注意本界面使用的是md内的图标。没有登录界面的图片 添加对应的viewmodel 添加文件Mytodo.ViewModels.LoginViewModel.cs 注册视图 添加启动 修改文件:App.xmal.cs

    2024年02月14日
    浏览(37)
  • WPF实战学习笔记16-数据加载

    新建Update事件,增加Prism事件列表 新建文件Mytodo/Common/Events/UpdateLoadingEvent.cs 新建含加载窗体基类 新建文件Mytodo/ViewModels/NavigationViewModel.cs 建立数据加载窗体扩展方法 新建文件Mytodo/Extensions/DialogExtension.cs 主窗口命名 修改文件Mytodo/Extensions/DialogExtension.cs 主窗口订阅消息 修改文

    2024年02月15日
    浏览(39)
  • WPF实战学习笔记04-菜单导航

    添加文件与文件夹 添加文件夹 ​ ./Extensions 添加文件 类型:用户控件 ./Views/IndexView.xaml ./Views/MemoView.xaml ./Views/TodoView.xaml ./Views/SettingsView.xaml ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./Extensions/PrismManager.cs 建立View与Vie

    2024年02月16日
    浏览(69)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包