创建一个用户控件

1. behindcode指定this.DataContext=XXViewModel

2. "{Binding DataContext.EditModel.MId,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"

Xaml代码如下:

<Grid Name="eg" Grid.Row="4" Grid.ColumnSpan="8"  Visibility="{Binding DataContext.EditVisible,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Label Content="年月:" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"></Label>
            <Label Content="机种:" Grid.Column="2" Grid.Row="0" VerticalAlignment="Center"></Label>
            <Label Content="EMS邮件内容:" Grid.Column="4" Grid.Row="0" VerticalAlignment="Center"></Label>

<DatePicker Background="Blue"  Grid.Row="0" Grid.Column="1" SelectedDate="{Binding DataContext.EditModel.Monthly,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"></DatePicker>
            <ComboBox DisplayMemberPath="Value"  SelectedValuePath="Key" Grid.Row="0" Grid.Column="3"
                      SelectedValue="{Binding DataContext.EditModel.MId,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"  ItemsSource="{Binding DataContext.MachineList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>

WPF绑定Model的实例对象的更多相关文章

  1. 在接口中的静态方法来获取model的实例对象

    直接先上代码: 接口代码 abstract class BaseModel { /** * @var null */ protected static $_instances = Array(); / ...

  2. WPF绑定xaml中绑定对象需用属性表示,字段不可以绑定

    在练习WPF绑定时发现对象属性可以在XAML中绑定,但字段是不可以绑定: 比如: private Person person{get;set;}  可以绑定到XAML中,<TextBox Nam ...

  3. 利用反射和泛型把Model对象按行储存进数据库以及按行取出然后转换成Model 类实例 MVC网站通用配置项管理

    利用反射和泛型把Model对象按行储存进数据库以及按行取出然后转换成Model 类实例 MVC网站通用配置项管理   2018-3-10 15:18 | 发布:Admin | 分类:代码库 | 评论: ...

  4. 【WPF学习】第三十章 元素绑定——绑定到非元素对象

    前面章节一直都在讨论如何添加链接两个各元素的绑定.但在数据驱动的应用程序中,更常见的情况是创建从不可见对象中提取数据的绑定表达式.唯一的要求是希望显示的信息必须存储在公有属性中.WPF数据绑定数据结构 ...

  5. Wpf 数据绑定简介、实例1

    简介:1.WPF绑定使用的源属性必须是依赖项属性,这是因为依赖项属性具有内置的更改通知支持,元素绑定表达式使用了Xaml扩展标记, WPF绑定一个控件是使用Binding.ElementName, 绑 ...

  6. WPF 绑定

    WPF里分三种Binding:Binding, PriorityBinding, MultiBinding,这三种Binding的基类都是BindingBase,而BindingBase又继承于Mar ...

  7. vue构造函数(根实例化时和组件实例对象选项)参数:选项详解

    实例选项(即传给构造函数的options):数据,DOM,生命周期钩子函数,资源,组合,其他 数据 data 属性能够响应数据变化,当这些数据改变时,视图会进行重渲染. 访问方式: 1.通过 vm.$ ...

  8. 【转】【WPF】WPF绑定用法

    一.简介 为了后面行文顺利,在进入正文之前,我们首先对本文所涉及到的绑定知识进行简单地介绍.该节包含绑定的基本组成以及构建方式. WPF中的绑定完成了绑定源和绑定目标的联动.一个绑定常常由四部分组成: ...

  9. WPF快速入门系列(4)——深入解析WPF绑定

    一.引言 WPF绑定使得原本需要多行代码实现的功能,现在只需要简单的XAML代码就可以完成之前多行后台代码实现的功能.WPF绑定可以理解为一种关系,该关系告诉WPF从一个源对象提取一些信息,并将这些信 ...

随机推荐

  1. vs 数据库链接Web.config 配置

    1.使用Windows身份验证 <add name="SQLConnectionString" connectionString="Data Source=U5MJ ...

  2. DFS ZOJ 1002/HDOJ 1045 Fire Net

    题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...

  3. UIBarButtonItem不能获取frame

    在使用KxMenu这个厉害的控件做竖直列表的时候,发现UIBarButtonItem不能获取到frame,UIBarButtonItem是NSObject的子类,他不是一个uiresponed或者ui ...

  4. java 文件md5+字符串md5 实现

    import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; impo ...

  5. POJ2441 Arrange the Bulls(状压DP)

    题目是,有n头牛,每头牛都喜爱某几个草地,要把这n头牛分配给m个不同的它们喜爱的草地,问有几种分配方式. dp[n][S]表示前n头牛分配完毕后占用的草地集合是S的方案数 dp[0][0]=1 dp[ ...

  6. 【BZOJ】1027: [JSOI2007]合金(凸包+floyd)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1027 题意:$n$种材料,$m$种需求.每种材料有三个属性,给出三个属性的含量(和为1),问能否通过 ...

  7. in_array()和explode()的使用笔记

    今天使用explode函数是因为,在使用in_array()函数时候,in_array()的第二个参数是个数组,bool ( mixed $needle , array $haystack [, bo ...

  8. Linux启动过程中几个重要配置文件的执行过程

    Linux 登录后,配置执行顺序为(Debian Serials Capable):/etc/environment -> /etc/profile -> (~/.bash_profile ...

  9. [APAC]手动截取当前活动窗口,并且按规则命名(1/2)

    Function Take-ScreenShot { <# .SYNOPSIS Used to take a screenshot of the desktop or the active wi ...

  10. Scrum会议4

    组名称:天天向上 项目名称:连连看 参会成员:王森(Master)张金生 张政 栾骄阳 时间:2016.10.19 已完成内容: 1.连连看生成一关功能. 2.目前测试发现没有问题. 计划完成: 1. ...