I've got a XamlParseException
in some code which is trying to select all the text in a TextBox
.
Xaml:
Common:SelectAllTextOnFocus.IsTextSelectedOnFocus="True" />
Code behind:
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;
}
}
I get a XmalParseException, with the message: The type initializer for 'Common.SelectAllTextOnFocus' threw an exception.
Any ideas what's causing this, or how to go about debugging it?
The inner exception is: 'IsTextSelectedOnFocus' property was already registered by 'SelectAllTextOnFocus'.
This is being registered on creation in a static class - so how can it be being registered twice?