我有一个XamlParseException
在一些代码试图选择TextBox
中的所有文本。XamlParseException初始化一个静态类
的XAML:
常见:SelectAllTextOnFocus.IsTextSelectedOnFocus = “真”/>
后面的代码:
public static class SelectAllTextOnFocus
{
public static readonly DependencyProperty IsTextSelectedOnFocusProperty = DependencyProperty.RegisterAttached("IsTextSelectedOnFocus", typeof(bool), typeof(SelectAllTextOnFocus), new UIPropertyMetadata(false, OnIsTextSelectedOnFocusChanged));
public static bool GetIsTextSelectedOnFocus(TextBox item)
{
return (bool)item.GetValue(IsTextSelectedOnFocusProperty);
}
public static void SetIsTextSelectedOnFocus(TextBox item, bool value)
{
item.SetValue(IsTextSelectedOnFocusProperty, value);
}
static void OnIsTextSelectedOnFocusChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
{
var item = depObj as TextBox;
if (item == null)
{
return;
}
if (e.NewValue is bool == false)
{
return;
}
if ((bool)e.NewValue)
{
item.GotFocus += OnGotFocus;
}
else
{
item.GotFocus -= OnGotFocus;
}
}
我得到一个XmalParseException,与消息:“的类型初始Common.SelectAllTextOnFocus'抛出一个异常。
任何想法是什么导致了这一点,或者如何去调试呢?
内部异常是:'IsTextSelectedOnFocus'属性已被'SelectAllTextOnFocus'注册。
这是在创建静态类时注册的 - 那么它如何被注册两次?
有什么'InnerException.InnerException'? – SLaks 2010-10-14 12:26:00
我已经添加了内部异常消息。 – 2010-10-14 12:33:28