(一) WPF中TextBox控件与TextBlock控件值的绑定
2008-11-17 22:09
253 查看
代码如下:
<Window x:Class="TextBoxBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox x:Name="Input" Text="Please input text!" Grid.Row="0"></TextBox>
<TextBlock x:Name="Output1" Text="{Binding ElementName=Input, Path=Text}" Grid.Row="1"></TextBlock>
</Grid>
</Window>
红色代码实现了TextBlock的Text属性与TextBox的Text属性的绑定. ElementName属性:指定当前XAML文档中任何以(x:Name)名称为ElementName值的对象为数据源。Path属性:与“数据源指定标记”一起使用,获取数据源中的成员(属性)。如果数据源对象继承了ICustomeTypeDescriptor接口,将会从接口中获取属性值,否则使用类反射获取。
也可以如下写法:
<TextBlock x:Name="Output1" Grid.Row="1">
<TextBlock.Text>
<Binding ElementName="Input" Path="Text"></Binding>
</TextBlock.Text>
</TextBlock>
本文出自 “木子纵横” 博客,请务必保留此出处http://muzizongheng.blog.51cto.com/856912/1333197
<Window x:Class="TextBoxBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox x:Name="Input" Text="Please input text!" Grid.Row="0"></TextBox>
<TextBlock x:Name="Output1" Text="{Binding ElementName=Input, Path=Text}" Grid.Row="1"></TextBlock>
</Grid>
</Window>
红色代码实现了TextBlock的Text属性与TextBox的Text属性的绑定. ElementName属性:指定当前XAML文档中任何以(x:Name)名称为ElementName值的对象为数据源。Path属性:与“数据源指定标记”一起使用,获取数据源中的成员(属性)。如果数据源对象继承了ICustomeTypeDescriptor接口,将会从接口中获取属性值,否则使用类反射获取。
也可以如下写法:
<TextBlock x:Name="Output1" Grid.Row="1">
<TextBlock.Text>
<Binding ElementName="Input" Path="Text"></Binding>
</TextBlock.Text>
</TextBlock>
本文出自 “木子纵横” 博客,请务必保留此出处http://muzizongheng.blog.51cto.com/856912/1333197
相关文章推荐
- (一) WPF中TextBox控件与TextBlock控件值的绑定
- C# WPF TextBox控件与变量的绑定
- Wpf TextBox 控件如何绑定 Dictionary <int, string>
- 潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据
- C# WPF MVVM 实战 – 5- 用绑定,通过 VM 设置 View 的控件焦点
- WPF中控件绑定XML文件,实现修改XML文件即可以改变程序控件内容
- WPF常用数据绑定控件集合
- CYQ.Data 支持WPF相关的数据控件绑定(2013-08-09)
- .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
- WPF密码控件PasswordBox之 MVVM绑定使用
- WPF控件与控件值的绑定
- WPF学习笔记(04) - 简单的控件和数据绑定
- Windows Presentation Foundation(WPF)中的数据绑定(控件与控件值的绑定)
- WPF绑定各种数据源之元素控件属性
- WPF自定义控件,将该控件中包含的控件的某个属性绑定到自定义的属性对外暴露
- Silverlight/wpf DataGrid TextBox 等控件内容 Binding 中日期格式 StringFormat
- 让WPF的TextBox控件可以使用System.Windows.Forms.FontDialog设置样式
- WPF控件开发(1) TextBox占位符
- .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
- IronPython+WPF 修改ListView 中的CheckBox和TextBox等控件的使得数据实时更新的办法