总结:WPF中模板需要绑定父级别的ViewModel该如何处理
原文:总结:WPF中模板需要绑定父级别的ViewModel该如何处理
-
<ListBox ItemsSource="{Binding ClassCollection}">
-
<ListBox.ItemContainerStyle>
-
<Style TargetType="{x:Type ListBoxItem}">
-
<Setter Property="Height" Value="30"/>
-
<Setter Property="Template">
-
<Setter.Value>
-
<ControlTemplate TargetType="ListBoxItem">
-
<Grid>
-
<Border x:Name="ItemBackground"
-
Background="{TemplateBinding Background}"
-
BorderBrush="{TemplateBinding BorderBrush}"
-
BorderThickness="{TemplateBinding BorderThickness}"/>
-
-
<CheckBox Content="{Binding Item2.Name}" IsChecked="{Binding Item1,Mode=TwoWay}">
-
<i:Interaction.Triggers>
-
<i:EventTrigger EventName="Checked">
-
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Control_CodeAutoGeneration}}, Path=DataContext.RelayCommand}"
-
CommandParameter="ClassSelectionChanged"/>
-
</i:EventTrigger>
-
-
<i:EventTrigger EventName="Unchecked">
-
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Control_CodeAutoGeneration}}, Path=DataContext.RelayCommand}"
-
CommandParameter="ClassSelectionChanged"/>
-
</i:EventTrigger>
-
</i:Interaction.Triggers>
-
</CheckBox>
-
-
</Grid>
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style>
-
</ListBox.ItemContainerStyle>
-
<i:Interaction.Triggers>
-
<i:EventTrigger EventName="SelectionChanged">
-
<i:InvokeCommandAction Command="{Binding RelayCommand}" CommandParameter="ClassSelectionChanged"/>
-
</i:EventTrigger>
-
</i:Interaction.Triggers>
-
</ListBox>
其中、需要在代码
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Control_CodeAutoGeneration}}, Path=DataContext.RelayCommand}" CommandParameter="ClassSelectionChanged"/>
处绑定的父级别,Control_CodeAutoGeneration是我自定义的控件的ViewModel里面的RelayCommand命令,通过如上传递可以调用到父级别的ViewModel的绑定属性或命令
总结:WPF中模板需要绑定父级别的ViewModel该如何处理的更多相关文章
- WPF中,如何将绑定源设置到单件实例
原文:WPF中,如何将绑定源设置到单件实例 WPF中,如何将绑定源设置到单件实例 周银辉 大概两个月前,曾有位朋友问我:如 ...
- WPF中DatePiker值绑定以及精简查询
WPF中DatePiker值绑定以及精简查询 1.WPF中DatePiker值绑定 Xaml中值绑定使用Text <DatePicker Text="{Binding strMinDa ...
- 关于WPF中ItemsControl系列控件中Item不能继承父级的DataContext的解决办法
WPF中所有的集合类控件,子项都不能继承父级的DataContext,需要手动将绑定的数据源指向到父级控件才可以. <DataGridTemplateColumn Header="操作 ...
- javascript父级鼠标移入移出事件中的子集影响父级的处理方法
一.我们先分析其产生的原因: 1.当鼠标从父级移入子集时触发了父级的两个事件:a.父级的mouseout事件(父级离开到子集):b.由于事件冒泡影响,又触发了父级的mouseover事件(父级移入父级 ...
- WPF中ListBox的绑定
WPF中列表式控件派生自ItemsControl类,继承了ItemsSource属性.ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值(所有可被迭代遍历的集合都 ...
- wpf中的datagrid绑定操作按钮是否显示或者隐藏
如图,需要在wpf中的datagrid的操作那列有个确认按钮,然后在某些条件下确认按钮可见,某些情况下不可见的,放在mvc里直接在cshtml页面中if..else就行了. 但是在wpf里不行..网上 ...
- WPF中使用ObjectDataProvider绑定方法
ObjectDataProvider提供了绑定任意.net类型的功能,具体功能如下: 1.ObjectDataProvider提供了绑定任意CLR类型的公嫩那个. 2.它可以再XAML中利用生命史的语 ...
- WPF中模板选择和DataContext的一些使用
如图样: View结构 MainView(MainViewModel)|---Guide1View(Guide1ViewModel)|---Guide2View(Guide2ViewModel) |- ...
- wpf 中的DataTemplate 绑定控件
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...
随机推荐
- Linux用户环境配置文件
用户操作环境配置文件: 从/etc/skel目录复制过来 .bashrc 打开新终端 /etc/bashrc .bash_profile 用户登 ...
- nginx性能调优关键功能
1. expires缓存时间优化作用:通过在服务器上设置合理的expires缓存时间.适合缓存的类型:静态文件:html,图片,js,css,xml都是缓存对象.优点:能够让用户不必每次访问都要重新 ...
- 判断cms-暴库-后台查找-密码破解
1.判断网站CMS类型 判断目标 使用工具: 脚本语言 wvs 御剑 domain明小子 操作系统 wwwscan 啊d pangolin(穿山甲) 搭建平台 站长工具 netpark ...
- VUE的element-ui的使用
我们在自己的网站当中有的时候会用到element-ui的组建 1.如何安装element-ui的组件 在命令行工具当中输入cnpm i element-ui -S, 等待安装 2.如何在vue当中使用 ...
- vue-router路由高亮效果
审查代码,查看激活类名 (1)设置激活类名样式 (2)也可以在路由文件里配置激活类名的别名 (3)配置别名后再次审查,如下所示 此时可以直接配置active类名样式即可 此时便可以实现路由高亮效果 .
- 从0到1的开发,社交App 完成
内容概要 GitHub链接:GitHub链接 客户端使用Android Studio 服务端使用IDEA + SpringBoot + MyBaits 完成功能 添加好友,即时聊天,社交广场 只是一个 ...
- CentOS7.5 上使用 bundle 文件安装 MySQL8.0 MySQL5.0
CentOS7.5 上使用 bundle 文件安装 MySQL8.0 MySQL5.0 CentOS7.5 环境 [root@instance-fjii60o3 ~]# rpm -qi centos- ...
- 洛谷 CF997A Convert to Ones
洛谷 CF997A Convert to Ones 洛谷传送门 题意翻译 给你一个长度为 nn 的01串( n \leq 310^5n*≤3∗105 ),你有两种操作: 1.将一个子串翻转,花费 XX ...
- 自用ftp上传脚本
#!/bin/sh backupserver=$1 #localdir=ftp_result_tmp username=$3 password=$4 #remodir='./Log/2018-01-2 ...
- iptables 的几个状态
iptables的状态跟踪连接有4种,分别是:NEW.ESTABLISHED.RELATED.INVALID,除了从本机出去的数据包有NAT表的OUTPUT链处理外,其它所有的状态跟踪都在NAT表中的 ...