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

  • 相关阅读:
    Cannot change network to bridged: There are no un-bridged host network adapters解决方法
    The authenticity of host 192.168.0.xxx can't be established.
    Vm下 linux与windowsxp文件共享的方法
    vmware 下的linux的host only上网配置
    VMWare三种工作模式 :bridge、host-only、nat
    云技术入门指导:什么是云计算技术,云技术用什么语言开发
    什么是移动云计算
    云计算是什么
    架构之路
    这首诗看着是越看越顺眼,百赋乐其中
  • 原文地址:https://www.cnblogs.com/gisalameda/p/1872898.html
Copyright © 2011-2022 走看看