I am using a RadPropertyGrid. I am trying to use the AutoGeneratingPropertyDefinition event to provide a custom EditorTemplate with a textbox. I want to add a handler to the TextChanged event of the textbox but my event handler is never being called.
Relevant code:
I am using the 2012.2.912.35 version of the telerik dlls
Relevant code:
public
void
GeneratingProperty(AutoGeneratingPropertyDefinitionEventArgs e)
{
try
{
AvailableProperties property = (AvailableProperties)Enum.Parse(
typeof
(AvailableProperties), e.PropertyDefinition.Binding.Path.Path);
if
(IsAvailable(item.GetAvailableProperties(), property))
{
switch
(property)
{
case
AvailableProperties.Title:
FrameworkElementFactory textBoxFactory =
new
FrameworkElementFactory(
typeof
(TextBox));
textBoxFactory.AddHandler(TextBox.TextChangedEvent,
new
TextChangedEventHandler(TitleTextChanged));
textBoxFactory.SetValue(TextBox.BackgroundProperty, System.Windows.Media.Brushes.Tomato);
textBoxFactory.SetValue(TextBox.BorderBrushProperty, System.Windows.Media.Brushes.Transparent);
textBoxFactory.SetBinding(TextBox.TextProperty,
new
Binding(
"Title"
));
DataTemplate template =
new
DataTemplate();
template.VisualTree = textBoxFactory;
template.Seal();
e.PropertyDefinition.EditorTemplate = template;
e.PropertyDefinition.OrderIndex = 0;
e.PropertyDefinition.DisplayName =
"Title"
;
e.PropertyDefinition.Description =
"The title of the attribute. Can only contain letters, numbers, and underscores."
;
break
;
default
:
// other properties go in case statements above here
break
;
}
}
else
{
e.Cancel =
true
;
}
}
catch
{
e.Cancel =
true
;
}
}
public
void
TitleTextChanged(
object
sender, TextChangedEventArgs e)
{
if
(sender
is
TextBox)
{
TextBox titleTextBox = (TextBox)sender;
int
caretIndex = titleTextBox.CaretIndex;
string
newValue = titleTextBox.Text;
item.Title = newValue;
ApplyCorrectedValue(newValue, item.Title, titleTextBox, caretIndex);
NotifyOfPropertyChange(() => MappingsPanel);
}
else
{
Logger.Log(
"TitleChanged: source must be a TextBox"
);
throw
new
ArgumentException(
"source must be a TextBox"
);
}
}