文本框数据绑定到字符串依赖项参数不起作用 [英] Text Box data binding to the string dependency parameter is not working
本文介绍了文本框数据绑定到字符串依赖项参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用字符串控件绑定文本框时,在文本框中更改的文本不会显示在消息框中.代码片段为:
//.xaml文件
When I try to bind a text box with the string control, the text changed in the text box is not displayed in the messagebox. The code snippets are:
//The .xaml file
<Window x:Class="Databinding3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="207" Width="300">
<Grid>
<StackPanel Margin="28,44,20,36" Name="stackPanel1" Orientation="Horizontal">
<TextBox Height="23" Name="textBox1" Width="120" Text="{Binding Path=FullName}"/>
<Separator Width="20" Visibility="Hidden"></Separator>
<Button Height="23" Name="button1" Width="75" Click="button1_Click">Button</Button>
</StackPanel>
</Grid>
</Window>
.cs文件
The .cs file
namespace Databinding3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public string FullName
{
get { return (string)GetValue(FullNameProperty); }
set { SetValue(FullNameProperty, value); }
}
// Using a DependencyProperty as the backing store for FullName. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FullNameProperty =
DependencyProperty.Register("FullName", typeof(string), typeof(Window1), new UIPropertyMetadata(string.Empty));
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(FullName, "Full Name");
}
}
}
推荐答案
在哪里设置文本框以将窗口用作数据上下文? IMO,这对现实世界代码不是有用的.
Where do you set the Textbox to use the window as it''s data context ? This is not useful real world code, IMO.
我是WPF的初学者.您能否帮助我如何将数据上下文设置为文本框
I am the beginner in WPF. Can you plese help me in how to set the data context to the text box
这篇关于文本框数据绑定到字符串依赖项参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文