zoukankan      html  css  js  c++  java
  • WPF绑定Model的实例对象

    创建一个用户控件

    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}}}"/>

  • 相关阅读:
    Sqli-labs Less-28a 绕过unions+select过滤 union注入
    eclipse安装freemarker-ide插件
    Eclipse调试时出现source not found的问题
    POJ 1509 Glass Beads 后缀自动机 模板 字符串的最小表示
    1028/3/7 被踩爆的省选模拟赛 30分
    字符串的模板 Manacher kmp ac自动机 后缀数组 后缀自动机
    2018/3/6 省选模拟赛 60分
    埃及分数 a* 搜索 知识点mark
    UOJ #35. 后缀排序 后缀数组 模板
    BZOJ 4566 JZYZOJ 1547 [haoi2016T5]找相同子串 后缀数组 并查集
  • 原文地址:https://www.cnblogs.com/jeffry/p/5821269.html
Copyright © 2011-2022 走看看