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

  • 相关阅读:
    Ubuntu 设置网卡固定IP
    gawk Notes(2)
    再读simpledb 之 存储的实现
    [zZ]HDFSRAID使用Erasure Code来实现HDFS的数据冗余
    初识gawk, gawk Notes(1)
    gawk notes(3)
    Shell Notes(2)
    凶残的突击面试
    Google 图片下载工具
    Shell Notes(3)
  • 原文地址:https://www.cnblogs.com/jeffry/p/5821269.html
Copyright © 2011-2022 走看看