WPF 列表控件中的子控件上下文绑定
<DataGrid Grid.ColumnSpan="" Grid.Column="" Grid.Row="" Grid.RowSpan="" Height="Auto"
SelectedItem="{Binding Path=SelectProductModel,Mode=TwoWay}"
ItemsSource="{Binding Path=ArriveProductModels,Mode=TwoWay}"
Cursor="Hand" HeadersVisibility="Column" AutoGenerateColumns="False" CanUserAddRows="False" SelectionUnit="FullRow" >
<DataGrid.Columns>
<DataGridTextColumn Header="产品类别" Width="" Binding="{Binding Path=product_catalog_id,Mode=OneWay, Converter={StaticResource CatalogIdToNameCvter}}"/>
<DataGridTextColumn Header="进仓票号" Width="" Binding="{Binding Path=into_warehouse_no,Mode=OneWay}"/>
<DataGridTemplateColumn Header="操作" Width="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="移除"
Command="{Binding DataContext.RemoveProductCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
当前项目中,绑定一个ViewModel,
RemoveProductCommand为ViewModel中的属性,
ArriveProductModels也为ViewModel中的属性,这样就造成command绑定无效,因为找不到,这个时候需要
RelativeSource
Command="{Binding DataContext.RemoveProductCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
这样就可以绑定成功了,同样,将Button改为Combox,那么Combox的ItemSource
ItemSource={Binding DataContext.xxxx(数据源集合)
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}
}
WPF 列表控件中的子控件上下文绑定的更多相关文章
- JS获取用户控件中的子控件Id
用户控件 <asp:HiddenField ID="hfGradeId" runat="server" /> <asp:HiddenField ...
- pyqt5-复合控件中的子控件
天子骄龙
- wpf 寻找某个控件下的子控件
/// <summary> /// 寻找某个控件下的子控件 /// </summary> /// <typeparam name="ChildType" ...
- Repeater 模板中查找子控件
前言:对于Repeater控件,相信从事NETWeb开发的同仁们再熟悉不过了.因其呈现方式和Literal一样,并不在前端生成任何表单标签元素,所以属于比较轻量级的控件.不过青睐于Repeater的主 ...
- 浅析:点击父控件时,子控件中的textview自动进入选中状态
原因:父控件属性android:clickable="true",而textview之类的自控件默认不可点击,没有独立的点击监听,这样选中父控件时,textview之类的子控件也进 ...
- qt 给父窗体设置样式不影响子控件样式以及子控件设置透明
1.父窗体样式不生效? this->setAttribute(Qt::WA_StyledBackground); 2.父窗样式体影响子控件? this->setStyleSheet(&qu ...
- Activity中获取当前Fragment 中的子控件
XXXAdapter中 增加 public Fragment currentFragment; @Override public void setPrimaryItem(ViewGroup conta ...
- 【WPF】ListBox使用UserContrl作为子控件,引入UserContrl界面
<ListBox x:Name="housePlansLB" Margin="0" ItemsSource="{Binding HousePla ...
- WinForm------GridControl控件中使用SearchLookUpEdit控件的方法
1.在数据库添加两张表,拥有主外键关系 主键表: 外键表: 2.往工具栏里拖出GridCont控件,并增加相应的列,这里对"省份"进行修改,"FileName" ...
随机推荐
- ZOJ 3827 Information Entropy 水题
Information Entropy Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/sh ...
- 2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc20 ...
- [Practical Git] Switching between current branch and last checkout branch
When working on a project, it is much easier to work on features and bugs in isolation of the rest o ...
- epoll讲解
首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象. 不管是文件,还是套接字,还是管道,我们都可以把他们看作流. 之后我们来讨论I ...
- QUiLoader 动态加载.ui文件
动态加载UI文件是指,用 Qt Designer 通过拖拽的方式生产.ui 文件.不用 uic工具把.ui 文件变成等价的 c++代码,而是在程序运行过程中需要用到UI文件时,用 QUiLoader ...
- 【转】频点CTO张成:基于Cocos2d的MMORPG开发经验
http://www.9ria.com/plus/view.php?aid=27698 作者: zhiyuanzhe3 发表时间: 2013-06-29 17:46 6月29日,由9Tech社区.51 ...
- (手写识别) Zinnia库及其实现方法研究
Zinnia库及其实现方法研究 (转) zinnia是一个开源的手写识别库.采用C++实现.具有手写识别,学习以及文字模型数据制作转换等功能. 项目地址 [http://zinnia.sourcefo ...
- 详解 Objective-C 中的 Runtime
公司项目用到一个三方开源库,里面有个bug,不能改动源码,我想来想去,只能通过runtime这个万能的手段来解决.但是runtime 并不怎么会用,怎么办,马上学习呗.说到runtime,它是Obje ...
- A+B Problem III
描述 求A+B是否与C相等. 输入 T组测试数据. 每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0) 数 ...
- Thinkphp kindeditor 内容转义
参考了:[解决]ThinkPHP整合Html编辑器时出现自动转义的问题 遇到问题也是保存到数据库中的内容,会转义成“\"” 使用 $data['content'] = stripslashe ...