wpf prism 《3》 弹窗 IOC

news2024/9/24 11:29:46

传统的弹窗 这种耦合度高

new 窗体() . Show();
new 窗体() . ShowDialog();

利用Prism 自动的 IOC 弹窗的 必须 必须 必须 页面控件

在这里插入图片描述
弹窗的 必须 必须 必须 页面控件
弹窗的 必须 必须 必须 页面控件
弹窗的 必须 必须 必须 页面控件
弹窗的 必须 必须 必须 页面控件
》》否则 报上面的错误

在这里插入图片描述
在这里插入图片描述
》》主程序

<Window x:Class="BlankApp2.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://prismlibrary.com/"
        prism:ViewModelLocator.AutoWireViewModel="True"
        Title="{Binding Title}" Height="350" Width="525" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
            <Button Content="弹窗1" Command="{Binding OpenCommand}" CommandParameter="Popup"></Button>
            <Button Content="弹窗2" Command="{Binding OpenCommand}" CommandParameter="UCPopup"></Button>
            <!--<Button Content="模块Student" Command="{Binding OpenCommand}" CommandParameter="ViewXX"></Button>
            <Button Content="模块C" Command="{Binding OpenCommand}" CommandParameter="ViewC"></Button>
            <Button Content="回退" Command="{Binding BackCommand}"></Button>-->
        </StackPanel>
        <ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion" />
    </Grid>
</Window>

》》主程序对应的 ViewModel

using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Navigation.Regions;
using System;
namespace BlankApp2.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private string _title = "Prism Application";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        public DelegateCommand<string> OpenCommand { get; private set; }
        public IDialogService DialogService { get; }
        public MainViewModel(IDialogService dialogService)
        {
            this.DialogService = dialogService;
            this.OpenCommand = new DelegateCommand<string>(Open);

        }
        private void Open(string obj)
        {
            //传递给弹窗的参数信息
            DialogParameters keys = new DialogParameters();
            keys.Add("zen", "============zen============");
            DialogService.ShowDialog(obj, keys, callback =>
            {
                if (callback.Result == ButtonResult.OK)
                {   
                   //弹窗传递的参数信息
                    string ss = callback.Parameters.GetValue<string>("Info");
                }
            });
        }


    }
}

》》》弹窗用户控件 、弹窗的ViewModel
在这里插入图片描述

<UserControl x:Class="BlankApp2.Views.UCPopup"
             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:BlankApp2.Views"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="80"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBlock Text="{Binding Title}"></TextBlock>
        <TextBlock Text="弹窗信息" FontSize="40" Grid.Row="1"></TextBlock>
        <StackPanel Orientation="Horizontal" Margin="10" HorizontalAlignment="Right" Grid.Row="2">
            <Button Content="确     定" Margin="10" Command="{Binding OKCommand}"></Button>
            <Button Content="取     消" Margin="10" Command="{Binding CancelCommand}"></Button>
        </StackPanel>
    </Grid>
</UserControl>

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

namespace BlankApp2.ViewModels
{
    public class UCPopupViewModel : IDialogAware
    {
        public string Title { get; set; }
        public DialogCloseListener RequestClose { get; set; }
        public DelegateCommand CancelCommand { get; set; }
        public DelegateCommand OKCommand { get; set; }
        public UCPopupViewModel()
        {
            CancelCommand = new DelegateCommand(Cancel);
            OKCommand = new DelegateCommand(OKcmd);
        }
        private void OKcmd()
        {
            DialogParameters keys = new DialogParameters();
            keys.Add("Info", "======INDO==========");
            RequestClose.Invoke(keys, ButtonResult.OK);
        }

        private void Cancel()
        {
            RequestClose.Invoke(ButtonResult.Cancel);
        }
        //是否准许关闭弹窗
        public bool CanCloseDialog()
        {
            return true;
        }
        //弹窗关闭时【窗体哪个 X】
        public void OnDialogClosed()
        {
            DialogParameters keys = new DialogParameters();
            keys.Add("Info", "======INDO==========");
            RequestClose.Invoke(keys, ButtonResult.OK);
            //throw new NotImplementedException();
        }
        //弹窗弹出时触发
        public void OnDialogOpened(IDialogParameters parameters)
        {
            if (parameters.ContainsKey("zen"))
            {
                this.Title = parameters.GetValue<string>("zen");
            }
            //throw new NotImplementedException();
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2084409.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

sql-labs41-45关通关攻略

第41关 一.查询数据库 http://127.0.0.1/Less-41/?id-1%20union%20select%201,2,database()--http://127.0.0.1/Less-41/?id-1%20union%20select%201,2,database()-- 二.查表 http://127.0.0.1/Less-41/?id-1%20union%20select%201,2,(select%20group_concat(table_name)…

【Java】—— Java面向对象基础:Java中类的构造器与属性初始化,Student类的实例

目录 定义Student类 在main方法中创建Student对象 结论 在Java中&#xff0c;类的构造器&#xff08;Constructor&#xff09;是一个特殊的方法&#xff0c;用于在创建对象时初始化对象的属性。今天&#xff0c;我们将通过一个简单的Student类实例&#xff0c;来探讨如何在J…

【数据分享】2000—2023年250米分辨率逐月归一化植被指数(NDVI)栅格数据(免费获取/全国/分省)

NDVI&#xff0c;全名为Normalized Difference Vegetation Index&#xff0c;中文名称为归一化植被指数。这个指数可以用来定性和定量评价植被覆盖及其生长活力&#xff0c;我们也可以简单地将它理解为体现植被密度和健康状况的一个指标。之前我们给大家分享了来源于MOD13A3数据…

手握15个大厂offer,我在大模型风口起飞

在“金三银四”的招聘季中&#xff0c;社交媒体上分享offer信息的“求助帖”比比皆是。帖子一般只披露公司名称和薪资区间&#xff0c;模糊具体岗位&#xff0c;作为判断是否值得去的衡量标准。 2024年毕业的985硕士生白丁&#xff08;化名&#xff09;一口气晒出了自己在秋招…

使用STM32CubeMX新建工程

开发板&#xff1a;STM32h743xi 编程软件&#xff1a;Keil、STM32CubeMX 项目&#xff1a;GPIO外设操作&#xff08;彩色LED灯&#xff09; 学习打卡&#xff1a;Day1 学习地址&#xff1a;【野火】STM32 HAL库开发实战指南 教学视频 手把手教学STM32全系列 零基础入门CubeMXHA…

echarts组件——漏斗图

echarts组件——漏斗图 组件代码 <template><div :class"classname" :style"{height:height,width:width}" /> </template><script> import * as echarts from echarts require(echarts/theme/macarons) // echarts theme import…

虚拟试穿(VTON)和虚拟换装(VD)技术分享

虚拟试穿技术&#xff08;VTON&#xff09;和虚拟换装&#xff08;VD&#xff09;技术是一种应用于电子商务和在线零售的技术&#xff0c;旨在通过数字手段提升用户的购物体验&#xff0c;让用户能够在没有实际试穿的情况下&#xff0c;看到自己穿上特定服装的样子。这种技术的…

js 如何获取文件名

"bbb/aaa/ss.pdf" 如何获取到文件名 ss.pdf split(/) 分割字符串 function getFileName(filePath) {// 使用正斜杠 / 分割路径&#xff0c;并获取最后一个元素作为文件名let parts filePath.split(/)// console.log(parts) // [bbb, aaa, ss.pdf]let fileName pa…

深度解析CancellationToken在HttpClient请求中的应用

概述 在现代的Web开发中&#xff0c;爬虫技术已成为数据获取的重要手段。随着Web技术的发展&#xff0c;服务器端的反爬机制也愈发复杂和智能化&#xff0c;因此&#xff0c;我们需要不断优化爬虫的设计和实现&#xff0c;以提高效率和稳定性。在本文中&#xff0c;我们将重点…

Windows中Git对文件名大小写不敏感的问题解决方法

文章目录 前言一、Git 对文件名大小写不敏感方法1.使用git命令进行修改方法2.关闭git 忽略大小写配置 &#xff08;可以当前项目设置&#xff0c;也可以全局设置 --global&#xff09; 二、新的问题&#xff08;重复的目录&#xff09;原因分析解决方法 前言 Git是一个免费的、…

wpf prism 《4》 事件 发布订阅

PubSubEvent 继承 EventBase TEventType GetEvent() where TEventType : EventBase, new();

Java使用POI创建不同类型单元格

这篇文章将演示如何使用POI 展示如何创建一个包含不同类型单元格&#xff08;如字符串、数字、日期、布尔值和公式&#xff09;的Excel文件&#xff0c;并设置单元格样式&#xff0c;包括字体、颜色、边框和对齐方式。 代码 import org.apache.poi.ss.usermodel.*; import org…

Leetcode5. 最长回文子串(背向指针)

问题描述&#xff1a; 给你一个字符串 s&#xff0c;找到 s 中最长的回文子串。 示例 1&#xff1a; 输入&#xff1a;s "babad" 输出&#xff1a;"bab" 解释&#xff1a;"aba" 同样是符合题意的答案。示例 2&#xff1a; 输入&#xff1a;…

医疗数字化转型数据中台架构方案(三)

为实现医疗数字化转型&#xff0c;我们将构建一个全面的数据中台架构&#xff0c;通过整合来自电子病历、影像系统、实验室数据及外部健康数据源的信息&#xff0c;应用大数据技术对数据进行统一存储、处理和分析&#xff1b;该数据中台将采用云计算和分布式架构&#xff0c;支…

MySQL:简述对事务的认识

浅谈对Spring事务的认识&#xff1a;https://xiaoer.blog.csdn.net/article/details/80849971 一、事务的特性 事务是数据库永恒不变的话题&#xff0c; ACID&#xff1a;原子性&#xff0c;一致性&#xff0c;隔离性&#xff0c;持久性。 &#xff08;1&#xff09;原子性&am…

DSLP——改变我团队的数据科学项目管理框架

到目前为止&#xff0c;它是数据科学的最佳框架。您可以将其用于您的团队或仅供您自己使用。以下是我使用它的方式。 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; 虽然软件工程实践要求问题的产生是为了适应不断变化的客户需求&#xff0c;但我们需要能…

护眼大路灯是不是智商税?全面测评书客、雷士、米家护眼大路灯

目前很多护眼大路灯存在虚标参数、夸大宣传&#xff0c;甚至一些质量低劣的产品还会对眼睛造成更严重的伤害。所以&#xff0c;究竟怎样才能买到一台真正好用的护眼大路灯呢&#xff1f;雷士护眼大路灯真的好吗&#xff1f;本次通过对书客、雷士、米家三款护眼大路灯的实测&…

ODOO17文档打印(输出)方案 -- ODOO17 document printing (output) scheme

根据使用场景不同&#xff0c;ODOO17支持以下几种文档打印(输出)方案&#xff1a; According to different usage scenarios, ODOO17 supports the following document printing (output) schemes: 1、QWEB ODOO原生打印功能&#xff08;生成PDF文档&#xff09; odoo使用的主…

JavaScript高阶 day-04

目录 一.什么是原型&#xff0c;什么是原型链&#xff1f; 二.call / apply / bind 有啥区别 三.JS四种检测数据类型的方式 四.说说继承 五.for..in和for..of和forEach的区别 六.forEach和map方法的区别 七. js高阶中数组的常用的操作方法 八.什么是严格模式 九.什么是…

深入了解Python数据可视化库——Seaborn

数据可视化在数据分析和机器学习领域中占据着重要地位,它不仅能帮助我们直观地理解数据,还能在探索数据、发现模式和趋势时提供极大的便利。Python语言中有多个优秀的可视化库,其中,Seaborn 因其简单易用且美观的图表风格而备受青睐。Seaborn是基于Matplotlib构建的高级API…