Wpf 使用 Prism 实战开发Day08

这篇具有很好参考价值的文章主要介绍了Wpf 使用 Prism 实战开发Day08。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

备忘录页面设计

1.效果图

Wpf 使用 Prism 实战开发Day08,WPF入门,wpf,ui,c#

一.布局设计跟第7章节一样,只是内容方面发生变化,其他样式都一样。直接把代码粘出来了

MemoView.xaml 页面代码

<UserControl x:Class="MyToDo.Views.MemoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyToDo.Views"
             mc:Ignorable="d" 
             xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             d:DesignHeight="450" d:DesignWidth="800">
    <md:DialogHost>
        <md:DrawerHost IsRightDrawerOpen="{Binding IsRightDrawerOpen}">
            <!--设计右边弹出层-->
            <md:DrawerHost.RightDrawerContent>
                <!--定义弹出层的内容区域-->
                <DockPanel Width="300" LastChildFill="False">
                    <TextBox md:HintAssist.Hint="请输入备忘录概要" Margin="20,0" DockPanel.Dock="Top"/>
                    <TextBox md:HintAssist.Hint="请输入备忘录内容" Margin="20" MinHeight="100" DockPanel.Dock="Top"/>
                    <Button Content="添加到备忘录"  DockPanel.Dock="Top" Margin="20,0" />
                </DockPanel>
            </md:DrawerHost.RightDrawerContent>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <StackPanel Margin="15,0,0,0" Orientation="Horizontal">
                    <TextBox Width="250" VerticalAlignment="Center" md:HintAssist.Hint="查找备忘录..." md:TextFieldAssist.HasClearButton="True"/>
                </StackPanel>
                <Button HorizontalAlignment="Right" Content="+ 添加备记录" Margin="10,5" Command="{Binding AddCommand}" />

                <ItemsControl Grid.Row="1" HorizontalAlignment="Center" ItemsSource="{Binding MemoDtos}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <!--自定义内容模板-->
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <!--自定义内容区域-->
                            <Grid Width="220" MinHeight="180" MaxHeight="250" Margin="8" >
                                <!--定义2行-->
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto"/>
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <!--右上角按钮-->
                                <md:PopupBox HorizontalAlignment="Right" Panel.ZIndex="1">
                                    <Button Content="删除"/>
                                </md:PopupBox>

                                <!--整个框圆角-->
                                <Border CornerRadius="3" Grid.RowSpan="2" Background="#11b038"/>

                                <TextBlock  Text="{Binding Title}" Padding="10,5" FontWeight="Bold"/>
                                <TextBlock Text="{Binding Content}" Padding="10,5" Grid.Row="1"/>
                                <!--白色背景底色控件-->
                                <Canvas Grid.RowSpan="2" ClipToBounds="True">
                                    <Border Canvas.Top="10" CornerRadius="100" Canvas.Right="-50" Width="120" Height="120" Background="#ffffff" Opacity="0.1"/>
                                    <Border Canvas.Top="80" CornerRadius="100" Canvas.Right="-30" Width="120" Height="120" Background="#ffffff" Opacity="0.1"/>
                                </Canvas>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>

        </md:DrawerHost>

    </md:DialogHost>
</UserControl>

二.后端测试数据生成,基本也跟第7章节一样,只是对应的实体类名称不一样。当前 MemoViewModel.cs 类源码如下:

  public class MemoViewModel : BindableBase
   {
       public MemoViewModel()
       {
           MemoDtos = new ObservableCollection<MemoDto>();
           CreateMemoList();
           AddCommand = new DelegateCommand(Add);
       }
       private bool isRightDrawerOpen;
       /// <summary>
       /// 右侧编辑窗口是否展开
       /// </summary>
       public bool IsRightDrawerOpen
       {
           get { return isRightDrawerOpen; }
           set { isRightDrawerOpen = value; RaisePropertyChanged(); }
       }


       public DelegateCommand AddCommand { get; private set; }
       private ObservableCollection<MemoDto> memoDtos;
       /// <summary>
       /// 创建数据的动态集合
       /// </summary>
       public ObservableCollection<MemoDto> MemoDtos
       {
           get { return memoDtos; }
           set { memoDtos = value; RaisePropertyChanged(); }
       }
       void CreateMemoList()
       {
           for (int i = 0; i < 20; i++)
           {
               memoDtos.Add(new MemoDto()
               {
                   Title = "标题" + i,
                   Content = "测试数据..."
               });
           }
       }
       /// <summary>
       /// 添加备忘录
       /// </summary>
       /// <exception cref="NotImplementedException"></exception>
       private void Add()
       {
           IsRightDrawerOpen = true;
       }

   }

三.添加页面滚动条,目前整个页面,如果内容超出页面范围,是不能进行滚动的。

     1. 在 ItemsControl 中,添加滚动条 ScrollViewer

Wpf 使用 Prism 实战开发Day08,WPF入门,wpf,ui,c#

 这样使用ScrollViewer 把内容区域包裹起来,就能让内容区域支持滚动了

      2. 添加滚动条后的效果图如下: 

Wpf 使用 Prism 实战开发Day08,WPF入门,wpf,ui,c#


四.添加动画,打开设备录或待办事项页面时,显示一个动画效果。

使用md 中的一个自带动画 md:TransitioningContent 来实现该功能 

  • 需要设置一个属性,OpeningEffect:打开的效果。并且该属性的值有很多种动画类型。例如,当前设置动画效果,Kind=ExpandIn

Wpf 使用 Prism 实战开发Day08,WPF入门,wpf,ui,c#

     1.在 DataTemplate 数据模板中,添加 md:TransitioningContent,表示在展示数据的时候添加一个动画效果。最后效果如下:

Wpf 使用 Prism 实战开发Day08,WPF入门,wpf,ui,c#文章来源地址https://www.toymoban.com/news/detail-774508.html

五.MemoView.xaml 完整源码

<UserControl x:Class="MyToDo.Views.MemoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyToDo.Views"
             mc:Ignorable="d" 
             xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             d:DesignHeight="450" d:DesignWidth="800">
    <md:DialogHost>
        <md:DrawerHost IsRightDrawerOpen="{Binding IsRightDrawerOpen}">
            <!--设计右边弹出层-->
            <md:DrawerHost.RightDrawerContent>
                <!--定义弹出层的内容区域-->
                <DockPanel Width="300" LastChildFill="False">
                    <TextBox md:HintAssist.Hint="请输入备忘录概要" Margin="20,0" DockPanel.Dock="Top"/>
                    <TextBox md:HintAssist.Hint="请输入备忘录内容" Margin="20" MinHeight="100" DockPanel.Dock="Top"/>
                    <Button Content="添加到备忘录"  DockPanel.Dock="Top" Margin="20,0" />
                </DockPanel>
            </md:DrawerHost.RightDrawerContent>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <StackPanel Margin="15,0,0,0" Orientation="Horizontal">
                    <TextBox Width="250" VerticalAlignment="Center" md:HintAssist.Hint="查找备忘录..." md:TextFieldAssist.HasClearButton="True"/>
                </StackPanel>
                <Button HorizontalAlignment="Right" Content="+ 添加备记录" Margin="10,5" Command="{Binding AddCommand}" />
                <ScrollViewer Grid.Row="1" >
                    <ItemsControl HorizontalAlignment="Center" ItemsSource="{Binding MemoDtos}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <!--自定义内容模板-->
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <md:TransitioningContent OpeningEffect="{md:TransitionEffect Kind=ExpandIn}">
                                    <!--自定义内容区域-->
                                    <Grid Width="220" MinHeight="180" MaxHeight="250" Margin="8" >
                                        <!--定义2行-->
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="auto"/>
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <!--右上角按钮-->
                                        <md:PopupBox HorizontalAlignment="Right" Panel.ZIndex="1">
                                            <Button Content="删除"/>
                                        </md:PopupBox>

                                        <!--整个框圆角-->
                                        <Border CornerRadius="3" Grid.RowSpan="2" Background="#11b038"/>

                                        <TextBlock  Text="{Binding Title}" Padding="10,5" FontWeight="Bold"/>
                                        <TextBlock Text="{Binding Content}" Padding="10,5" Grid.Row="1"/>
                                        <!--白色背景底色控件-->
                                        <Canvas Grid.RowSpan="2" ClipToBounds="True">
                                            <Border Canvas.Top="10" CornerRadius="100" Canvas.Right="-50" Width="120" Height="120" Background="#ffffff" Opacity="0.1"/>
                                            <Border Canvas.Top="80" CornerRadius="100" Canvas.Right="-30" Width="120" Height="120" Background="#ffffff" Opacity="0.1"/>
                                        </Canvas>
                                    </Grid>
                                </md:TransitioningContent>
                                
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
                
            </Grid>

        </md:DrawerHost>

    </md:DialogHost>
</UserControl>

到了这里,关于Wpf 使用 Prism 实战开发Day08的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

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

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

相关文章

  • Wpf 使用 Prism 实战开发Day12

    Wpf 使用 Prism 实战开发Day12

    控制器类需要继承  ControllerBase 基类 需要添加 [ ApiController]  特性以及 [ Route]  特性 Route (路由) 特性参数规则,一般写法是  [Route(\\\"api/[controller]/[action]\\\")] 。也就是路由访问路径:前缀api/当前控制器/具体的方法 为了业务处理逻辑和控制器之间实现解耦。可以通过设计:

    2024年01月16日
    浏览(11)
  • Wpf 使用 Prism 实战开发Day11

    Wpf 使用 Prism 实战开发Day11

     仓储(rep):仓储接口定义了对实体类访问数据库及操作的方法。它统一管理数据访问的逻辑,并与业务逻辑层进行解耦。 简单的理解就是对访问数据库的一层接口封装。 工作单元(uow):用来保证我们处理业务逻辑的,稳定性,完整性。防止在业务操作过程中,涉及对数据

    2024年02月02日
    浏览(19)
  • Wpf 使用 Prism 实战开发Day10

    Wpf 使用 Prism 实战开发Day10

    1-9章节已经把基本功能都做好了,但页面的数据是后台模拟生成的静态数据。接下来所有章节就是实现,页面的所有数据都是从数据库中获取,并且实现页面数据的持久化以及增删改查。 使用Sqlite 做为数据库  1.打开 MyToDo.Api项目,右键=》选择 管理NuGet 程序包 ,进行下载安

    2024年01月25日
    浏览(10)
  • Wpf 使用 Prism 实战开发Day19

    Wpf 使用 Prism 实战开发Day19

    由于待办事项功能页,数据已正常渲染出来了。但页面新增,查询,修改,删除等功能还未实现。本章节来实现页面的请求后台实现CURD(增删改查) 根据渲染出来的待办事项,点击对应的待办事项时,查找出该条数据,显展示在编辑窗口中。 同时在搜索框中输入的参数或选

    2024年04月23日
    浏览(11)
  • Wpf 使用 Prism 实战开发Day13

    Wpf 使用 Prism 实战开发Day13

    在上一节  ToDoController 控制器,或 IToDoService 服务接口中,方法的传参都是直接传的实体类。但在实际开发过程中,这样是不允许的。标准且规范的做法是,定义一个数据传输层,即Dto层。 1. 创建 BaseDto 基类,用于存放共用属性。 2. 创建待办事项 Dto类,并继承自 BaseDto 基类

    2024年01月20日
    浏览(27)
  • WPF超好用的框架Prism入门使用,上位机赶紧学起来!

    WPF框架Prism是一种用于开发模块化、可重用和可测试的WPF应用程序的框架。它提供了一种简单而强大的方式来管理复杂应用程序的代码和构建高度可扩展的应用程序。 如果您想使用Prism框架来开发WPF应用程序,需要学习以下几个方面: MVVM模式 :Prism基于MVVM模式,因此需要了

    2024年02月01日
    浏览(14)
  • WPF开发学生信息管理系统【WPF+Prism+MAH+WebApi】(四)

    WPF开发学生信息管理系统【WPF+Prism+MAH+WebApi】(四)

    最近通过WPF开发项目,为了对WPF知识点进行总结,所以利用业余时间,开发一个学生信息管理系统【Student Information Management System】。前三篇文章进行了框架搭建和模块划分,后台WebApi接口编写,以及课程管理模块开发,本文在前三篇基础之上,继续深入开发学生信息管理系统

    2024年02月04日
    浏览(8)
  • WPF开发之Prism详解【内附源码】

    WPF开发之Prism详解【内附源码】

    在实际应用开发中,随着项目业务逐渐复杂,耦合度会越来越高,维护成本也会直线上升,所以解耦也变得越来越重要。Prism框架为WPF开发中解耦提供了非常便捷的应用。今天主要以一个简单的小例子,简述WPF开发中Prism框架的简单应用,如有不足之处,还请指正。 Prism是一个

    2023年04月16日
    浏览(9)
  • WPF Prism的简单使用

    新建 WPF 项目,我是基于 .net 5.0-windows 创建的。 引入 Prism.DryIoc(8.1.97) 的 Nuget 包。 App.xaml 中引入命名空间。 将 App.xaml 中 Application 标签更改成 prism:PrismApplication 并去除 StartUri 属性,将 App.xaml.cs 中 Application 更改成 PrismApplication 。 实现 PrismApplication (实际上是 PrismApplicationBas

    2023年04月14日
    浏览(9)
  • WPF框架Prism的使用 二

    这是第二篇关于Prism-WPF的介绍,第一篇中我们简单介绍了Prism,然后讲述了如何搭建一个MVVM的简单页面程序。其实我写的文章就是把github上面的官方例子摘出来自己跑了一遍,然后加上了一些自己的理解,简单给大家分享一下。 下面放上传送门: 第一篇的链接 官方提供的示

    2024年04月10日
    浏览(13)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包