【发布时间】:2010-12-20 13:20:57
【问题描述】:
我有一个简单的用户控件
Xaml:
<UserControl x:Class="GraemeGorman_Controls.Navigation.NavigationItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border x:Name="borderLayoutRoot">
<TextBlock x:Name="textBlockCaption" Text="{Binding Caption}" />
</Border>
</UserControl>
Cs:
namespace GraemeGorman_Controls.Navigation
{
public partial class NavigationItem : UserControl
{
public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register(
"Caption",
typeof (string),
typeof (NavigationItem),
new PropertyMetadata(new PropertyChangedCallback(OnCaptionChanged)));
public string Caption
{
get {return (string)GetValue(CaptionProperty);}
set {SetValue(CaptionProperty, value);}
}
public NavigationItem()
{
InitializeComponent();
}
private static void OnCaptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//null
}
}
}
我的问题是,当我创建一个控件实例时,标题永远不会显示 - 现在我已经使用 e.NewValue 测试了 OnCaptionChanged 函数中的属性,它是正确的值。我的绑定有什么问题?
如果我在 set 的标题属性后面写代码
textBlockCaption.Text = value;
看起来不错……
任何帮助表示赞赏
谢谢 格雷姆
【问题讨论】:
标签: c# wpf silverlight binding user-controls