zoukankan      html  css  js  c++  java
  • WPF学习笔记<二>数据绑定

    • 1 bind a property of an element to itself
     1:  <Window x:Class="WpfApplication1.chap5_2"
     2:          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3:          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4:          Title="chap5_2" Height="300" Width="300">
     5:      <Grid>
     6:          <Slider Name="slider" 
     7:                      Margin="4" Interval="1" 
     8:                      TickFrequency="1" 
     9:                      IsSnapToTickEnabled="True"
    10:                      Minimum="0" Maximum="100"
    11:                      ToolTip="{Binding
    12:                                   RelativeSource =
    13:                                  { RelativeSource Self},
    14:                                 Path=Value}"/>
    15:      </Grid>
    16:  </Window>
    17:  
    其中Binding RelativeSource={RelativeSource Self}等价于Binding RelativeSource=
    {x:Static RelativeSource.Self}
    2010-11-09_140731 

    2 create a two-way binding

    2010-11-09_142338

     1:  <Window x:Class="WpfApplication1.chap5_2"
     2:          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3:          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4:          Title="chap5_2" Height="300" Width="300">
     5:      <Grid>
     6:          <Slider Name="slider" 
     7:                      Margin="4" Interval="1" 
     8:                      TickFrequency="1" 
     9:                      IsSnapToTickEnabled="True"
    10:                      Minimum="0" Maximum="100"/>
    11:              <!--    ToolTip="{Binding
    12:                                   RelativeSource =
    13:                                  { x:Static    RelativeSource.Self},
    14:                                 Path=Value}"/>-->
    15:        <StackPanel Orientation="Horizontal">
    16:                  <TextBlock 
    17:                      Width="Auto" HorizontalAlignment="Left"
    18:                      Margin="4" VerticalAlignment="Center" 
    19:                      Text="Gets and sets the value of the slider:" />
    20:                  <TextBox Width="31" HorizontalAlignment="Center" Margin="4"
    21:                             Text="{Binding
    22:                                          ElementName=slider,
    23:                                          Path=Value, 
    24:                                          Mode=TwoWay, 
    25:                                          UpdateSourceTrigger=PropertyChanged}" Height="25" />
    26:              </StackPanel>
    27:      </Grid>
    28:  </Window>
    29:  

    本例中,设置TextBox的 mode=TwoWay,可以实现在文本框中显示滑动条上的数据,也可修改文本框中数据使滑动条滑动到数据对应的指定位置。

    UpdateSourceTrigger指定事件触发更新的发生时间。

    2010-11-09_142558

  • 相关阅读:
    线性表ADT实现
    基数排序
    二叉树之已知前序和中序遍历求后序遍历(POJ2255 &&HDU )
    acm头文件
    快排
    快读
    二分
    数据结构大师
    AC_2. 01背包问题
    AC_94. 递归实现排列型枚举
  • 原文地址:https://www.cnblogs.com/gisalameda/p/1872898.html
Copyright © 2011-2022 走看看