zoukankan      html  css  js  c++  java
  • WPF数据绑定

    <Window x:Class="WPFBind.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:wpfbind="clr-namespace:WPFBind"
            xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
            Title="MainWindow" Height="780" Width="564">
        <Window.Resources>
            <wpfbind:RawCountToDescriptionConverter x:Key="myConverter"/>
        </Window.Resources>
        <StackPanel>
            
            <StackPanel>
                <TextBox Name="txt1"  Text="hello" />
                <Button Name="btn1" Content="{Binding ElementName=txt1, Path=Text }"></Button>
                <TextBox Name="btn2" Text="{Binding ElementName=txt1, Path=Text }"></TextBox>
            </StackPanel>
            <StackPanel>
                <Slider Name="slider1" Minimum="10" Maximum="100000" Value="10"></Slider>
                <TextBox Text="{Binding ElementName=slider1, Path=Value}"></TextBox>
            </StackPanel>
            <!--CLR绑定-->
            <StackPanel>
                <StackPanel.Resources>
                    <wpfbind:Person x:Key="eric" Name="Eric" />
                </StackPanel.Resources>
                <StackPanel.DataContext>
                    <Binding Source="{StaticResource eric}"></Binding>
                </StackPanel.DataContext>
                <Label  Content="{Binding Path=Name}" />
            </StackPanel>
            <!--RelativeSource-->
            <Grid x:Name="g1" Background="Red" Margin="10">
                <DockPanel x:Name="d1" Background="Orange" Margin="10">
                     <Grid x:Name="g2" Background="Yellow" Margin="10">
                        <DockPanel x:Name="d2" Background="LawnGreen" Margin="10">
                                <TextBox x:Name="textBox1" FontSize="24" Margin="10" 
                                         Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                    AncestorLevel=1, AncestorType={x:Type TextBox}}, Path=Name}">
                                </TextBox>
                        </DockPanel>
                        </Grid>
                </DockPanel>
            </Grid>
    
            <!--DataContext-->
            <StackPanel>
                <StackPanel.DataContext>
                    <wpfbind:Person x:Name="person" Name="Jessica" Age="18" ></wpfbind:Person>
                </StackPanel.DataContext>
                <Button Content="{Binding Path=Name}"></Button>
                <Button Content="{Binding Path=Age}"></Button>
            </StackPanel>
    
    
            <!--ItemsSource-->
            <StackPanel Background="LightBlue">
                <TextBlock Text="Student ID:" FontWeight="Bold"></TextBlock>
                <TextBox x:Name="txtbox1"></TextBox>
                <TextBlock Text="Student List:" FontWeight="Bold"></TextBlock>
                <ListBox x:Name="listBoxStudents"  Height="110"></ListBox>
            </StackPanel>
        </StackPanel>
      
    
    </Window>
  • 相关阅读:
    事务与数据库连接池DBCP和C3P0与工具类DBUtils
    JavaWeb基础JSP页面EL 和JSTL表达式
    Cookie和Session
    HttpServletRequest 和HttpServletResponse
    Http协议和Servlet
    Xml 和Tomcat
    Struts2第二天:Struts2的数据的封装、结果页面配置
    BootStrap基础知识总结
    Linux和Windows下Mysql数据库安装详解
    CSS 边框
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3435393.html
Copyright © 2011-2022 走看看