wpf prism 《3》 弹窗 IOC

传统的弹窗 这种耦合度高

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.mzph.cn/diannao/53034.shtml

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

相关文章

【C语言】十六进制、二进制、字节、位、指针、数组

【C语言】十六进制、二进制、字节、位 文章目录 [TOC](文章目录) 前言一、十六进制、二进制、字节、位二、变量、指针、指针变量三、数组与指针四、指针自加运算五、二维数组与指针六、指向指针的指针七、指针变量作为函数形参八、函数指针九、函数指针数组十、参考文献总结 前…

系统功能性能优化:从问题定位到解决方案的系统性分析

引言 在现代软件系统中&#xff0c;性能优化是确保系统稳定、响应迅速和资源高效利用的关键。面对复杂的系统架构和业务逻辑&#xff0c;进行性能优化往往需要遵循一系列系统性的步骤&#xff0c;以确保问题被准确识别&#xff0c;解决方案被有效实施。以下是一套专业的系统功…

(四)Kafka离线安装 - Kafka下载及安装

Kafka官方下载地址&#xff1a;Apache Kafka 这时候下载安装版本。 我这里的安装目录在 /usr/local/ cd /usr/local/# 创建目录 mkdir kafka cd kafka mkdir kafka_log 把下载的压缩包&#xff0c;放入到/usr/local/kafka/目录下&#xff0c;解压。 # 解压 tar -zxvf kafka…

前端踩坑记录:javaScript复制对象和数组,不能简单地使用赋值运算

问题 如图&#xff0c;编辑table中某行的信息&#xff0c;发现在编辑框中修改名称的时候&#xff0c;表格中的信息同步更新。。。 检查原因 编辑页面打开时&#xff0c;需要读取选中行的信息&#xff0c;并在页面中回显。代码中直接将当前行的数据对象赋值给编辑框中的表单对…

[从0开始AIGC][LLM]:LLM中Encoder-Only or Decoder-Only?为什么主流LLM是Decoder-Only?

LLM中Encoder-Only or Decoder-Only & 为什么主流LLM是Decoder-Only&#xff1f; 文章目录 LLM中Encoder-Only or Decoder-Only & 为什么主流LLM是Decoder-Only&#xff1f;1. 什么是Encoder-only、Decoder-Only2. 为什么当前主流的LLM都是Decoder-only的架构低秩问题 …

秋招/春招投递公司记录表格

最近在准备秋招&#xff0c;在各个平台投递秋招简历&#xff0c;什么官网&#xff0c;邮箱&#xff0c;boss&#xff0c;应届生各个平台上&#xff0c;投递的平台比较多&#xff0c;比较乱&#xff0c;因此自己想将这些平台投递记录都收集到一个表格上&#xff0c;所以在腾讯文…

bladeX默认审批流flowable如何设置

下面就是流程图必须得写 ${taskUser} 你要配什么 就给审批流的service传什么

VSCode必备插件!快看过来!

同学同学&#xff0c;你是不是也很头疼VSCode不知道安装什么插件啊&#xff1f;尤其是萌新小白&#xff0c;更是一头雾水&#xff0c;那就快来一起看看吧~我帮你整理了一些非常实用的插件&#xff0c;安装上它们&#xff0c;你的开发体验会大大提升&#xff01; 1. Chinese (S…

Call openai-node in the backend or call https in the frontend?

题意&#xff1a;在后端调用 openai-node 还是在前端调用 https&#xff1f; 问题背景&#xff1a; I have a web application by ReactJS and Nodejs. This application calls OpenAI APIs. 我有一个使用 ReactJS 和 Node.js 开发的 Web 应用程序。这个应用程序调用 OpenAI …

零基础入门转录组数据分析——预后模型之lasso模型

零基础入门转录组数据分析——预后模型之lasso模型 目录 零基础入门转录组数据分析——预后模型之lasso模型1. 预后模型和lasso模型基础知识2. lasso预后模型&#xff08;Rstudio&#xff09;——代码实操2. 1 数据处理2. 2 构建lasso预后模型2. 3 提取Lasso预后基因2. 4 计算风…

Pyqt5高级技巧:多线程任务、窗体交互、常用控件介绍(含基础Demo)

目录 一、多线程任务和多窗体交互 二、增删改查Demo 三、UI设计 【css效果代码对照表】 【实现效果】 【实现代码】 【常见问题】 Q1&#xff1a;工具栏怎么加&#xff0c;资源图片怎么加 Q2&#xff1a;控件被背景染色怎么办&#xff1f; Q3&#xff1a;QTdesigner有…

LVS的加权轮询算法

http://kb.linuxvirtualserver.org/wiki/Weighted_Round-Robin_Scheduling 加权轮循调度是为了更好地处理不同处理能力的服务器。每个服务器都可以被分配一个权重&#xff0c;一个表示处理能力的整数值。权值较高的服务器比权值较低的服务器首先接收到新连接&#xff0c;权值较…

<Rust>egui学习之小部件(七):如何在窗口中添加颜色选择器colorpicker部件?

前言 本专栏是关于Rust的GUI库egui的部件讲解及应用实例分析&#xff0c;主要讲解egui的源代码、部件属性、如何应用。 环境配置 系统&#xff1a;windows 平台&#xff1a;visual studio code 语言&#xff1a;rust 库&#xff1a;egui、eframe 概述 本文是本专栏的第七篇博…

记一次学习--webshell绕过(利用清洗函数)

目录 样本 样本修改 样本 <?php $a array("t", "system"); shuffle($a); $a[0]($_POST[1]); 通过 shuffle 函数打乱数组,然后通过$a[0]取出第一个元素&#xff0c;打乱后第一个元素可能是t也可能是system。然后再进行POST传参进行命令执行。 这里抓…

部署Rancher2.9管理K8S1.26集群

文章目录 一、实验须知1、Rancher简介2、当前实验环境 二、部署Rancher1、服务器初始化操作2、部署Rancher3、登入Rancher平台 三、Rancher对接K8S集群四、通过Rancher仪表盘部署Nginx服务1、创建命名空间2、创建Deployment3、创建Service 一、实验须知 1、Rancher简介 中文官…

【自由能系列(中级),代码模拟】预测编码的核心:三个关键方程式的详解

预测编码的核心&#xff1a;三个关键方程式的详解 ——探索预测编码背后的数学原理与应用 核心结论&#xff1a;预测编码是一种基于贝叶斯定理的理论框架&#xff0c;它通过三个关键方程式描述了大脑如何处理和解释来自环境的信号。这些方程式分别建立了贝叶斯定理的简化形式、…

9月新机首发:骁龙芯片+超大电池,游戏玩家的终极选择

随着秋风送爽的9月到来&#xff0c;智能手机和电子设备市场也迎来了新一轮的热潮。8月份的新机发布热潮刚刚退去&#xff0c;9月份的新机已经迫不及待地揭开了神秘的面纱。在众多备受期待的产品中&#xff0c;红魔品牌抢先官宣&#xff0c;两款全新的游戏平板将在9月5日正式亮相…

论文速读|通过人类远程操作的深度模仿学习框架:人型机器人的行走操纵技能

项目地址&#xff1a;Deep Imitation Learning for Humanoid Loco-manipulation through Human Teleoperation 本文详细介绍了 TRILL&#xff08;Teleoperation and Imitation Learning for Loco-manipulation&#xff09;框架&#xff0c;它是一个用于人型机器人行走操纵技能训…

OpenCV绘图函数(14)图像上绘制文字的函数putText()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 在图像上绘制指定的文本字符串。 cv::putText 函数在图像上绘制指定的文本字符串。无法使用指定字体渲染的符号会被问号&#xff08;?&#xff…

简单梯形问题

如下图&#xff0c;ABCD是一个梯形&#xff0c;E是AD的中点&#xff0c;直线CE把梯形分成甲、乙两部分&#xff0c;其面积之比为5:2&#xff0c;那么上底AB与下底CD的长度之比是&#xff08;&#xff09;。 A 2&#xff1a;5 B 3&#xff1a;5 C 3&#xff1a;4【正确答案】 D …