Hello,
In our project we must create a DataTemplate for a grid cell programmatically. Everything works perfect, but a click to a button within the template does not work.
Here is a snippet of the code:
var cellEditTemplate = new DataTemplate();
var dockPanel = new FrameworkElementFactory( typeof( DockPanel ) );
dockPanel.SetValue( DockPanel.LastChildFillProperty, true );
var textBlock = new FrameworkElementFactory( typeof( TextBlock ) );
textBlock.SetValue( FrameworkElement.StyleProperty, textBlockStyle );
textBlock.SetBinding( TextBlock.TextProperty, binding );
textBlock.SetValue( DockPanel.DockProperty, Dock.Left );
var button = new FrameworkElementFactory( typeof( RadButton ) );
button.SetValue( FrameworkElement.StyleProperty, buttonStyle );
button.SetValue( ContentControl.ContentProperty, "Press me" );
button.SetValue( FrameworkElement.MinWidthProperty, 0.0 );
button.SetValue( DockPanel.DockProperty, Dock.Right );
button.AddHandler( Button.ClickEvent,
new RoutedEventHandler( ( sender, args ) =>
{
int i = 0;
i++;
} ) );
button.SetValue( Button.CommandProperty );
dockPanel.AppendChild( button );
dockPanel.AppendChild( textBlock );
cellEditTemplate.VisualTree = dockPanel;
cellEditTemplate.Seal();
The event handler is not called.
Best regards,
Michael