我有一個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