【发布时间】:2010-03-02 18:09:51
【问题描述】:
我想创建一个带有 TextBox 的控件,并将 TextBox.Text 属性与我自己的依赖属性 TextProp 绑定。 (某种实验)但是,绑定不起作用!我做错了什么?
XAML:
<UserControl x:Class="WpfApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApplication1">
<TextBox Text="{Binding TextProp}" x:Name="textb"/>
</UserControl>
C#:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
TextProp = "fwef";
}
public string TextProp
{
get { return ( string )GetValue(TextPropProperty); }
set { SetValue(TextPropProperty, value); }
}
public static readonly DependencyProperty TextPropProperty =
DependencyProperty.Register("TextProp",typeof( string ),typeof(UserControl1));
}
【问题讨论】:
标签: c# wpf data-binding