我有一个附加属性,它似乎不允许我绑定到 Windows 8 中的附加属性。我可以在 Silverlight/WPF 中自由使用这种方式,但我不知道为什么它不会让我这样做。MSDN 论坛上的一篇帖子说它是通过 Windows 8 Release 修复的,我现在有这个版本,但它不会工作。它说“价值不在预期范围内”..
public static class CountHelper
{
public static readonly DependencyProperty TitleProperty =
DependencyProperty.RegisterAttached("Title", typeof (string), typeof (CountHelper), new PropertyMetadata(default(string)));
public static void SetTitle(UIElement element, string value)
{
element.SetValue(TitleProperty, value);
}
public static string GetTitle(UIElement element)
{
return (string) element.GetValue(TitleProperty);
}
}
XAML 文件
<TextBlock local:CountHelper.Title="Hello" Text="{Binding Path=(local:CountHelper.Title)}"/>