当前位置: 首页 > news >正文

WPF MVVM模式下如何将UI窗口变量传参到Viewmodel层

WPF MVVM模式下如何将UI窗口变量传参到Viewmodel层

UI层窗口定义

//窗口中绑定ViewModel<hc:GlowWindow.DataContext><viewmodel:MainWindowViewModel /></hc:GlowWindow.DataContext>//注册初始化事件<hc:Interaction.Triggers><hc:EventTrigger EventName="Loaded"><hc:EventToCommand Command="{Binding CmdLoaded}" PassEventArgsToCommand="True"/></hc:EventTrigger></hc:Interaction.Triggers>//需要传递到viewmodel层的UI控件<BorderGrid.Column="1"Margin="5"Background="{DynamicResource MainContentForegroundDrawingBrush}"><Grid x:Name="MainContent"></Grid></Border>//需要传递到viewmodel层的UI控件                <hc:DrawerName="DrawerSourceCode"Dock="Right"MaskCanClose="True"ShowMode="Push"><hc:ScrollViewer Width="700"><avalonEdit:TextEditorName="TextContainer"Margin="5"FontFamily="Consolas"FontSize="10pt"IsReadOnly="True"ShowLineNumbers="True"SyntaxHighlighting="C#" /></hc:ScrollViewer></hc:Drawer>

viewModel层

        // 控件private Grid MainContent;private TextEditor TextContainer;/// <summary>/// 关联控件 通过Lazy关键字 实现延迟初始化/// </summary>public RelayCommand<RoutedEventArgs> CmdLoaded => new Lazy<RelayCommand<RoutedEventArgs>>(() => new RelayCommand<RoutedEventArgs>(Loaded)).Value;private void Loaded(RoutedEventArgs e){MainContent = (e.Source as MainWindow).MainContent;TextContainer = (e.Source as MainWindow).TextContainer;}
http://www.lryc.cn/news/252481.html

相关文章:

  • 条款22:将成员变量声明为private
  • PTA 7-224 sdut-C语言实验-排序问题
  • 【JavaScript】3.2 JavaScript性能优化
  • pytorch bert实现文本分类
  • 《开箱元宇宙》:Madballs 解锁炫酷新境界,人物化身系列大卖
  • 4K-Resolution Photo Exposure Correction at 125 FPS with ~8K Parameters
  • 网络初识:局域网广域网网络通信基础
  • JVM之jps虚拟机进程状态工具
  • C++实现顺序栈的基本操作(扩展)
  • 用python写一个简单的爬虫
  • 分布式追踪
  • make -c VS make -f
  • Unity 代码控制Color无变化
  • 【Erlang进阶学习】2、匿名函数
  • 肖sir__mysql之视图__009
  • FPGA falsh相关知识总结
  • 升辉清洁IPO:广东清洁服务“一哥”还需要讲好全国化的故事
  • Python自动化办公:PDF文件的分割与合并
  • 破解app思路
  • 背景特效插件:Background Effects
  • 36.位运算符
  • C#异常处理-throw语句
  • PlantUML语法(全)及使用教程-时序图
  • 231204 刷题日报
  • PTA 7-229 sdut-C语言实验- 排序
  • 原生横向滚动条 吸附 页面底部
  • 1+x网络系统建设与运维(中级)-练习3
  • 知识图谱07——图片中表格开源ocr识别
  • 每日一练2023.12.4——正整数【PTA】
  • golang之net/http模块学习