Message.Attach on Controls in DataTemplate loaded with XamlReader

Dec 6, 2010 at 2:46 PM

I've got a WPF DataGrid whose columns are managed in the ViewModel because there is a variable # of columns.  One of the columns needs to be a TemplateColumn with 2 controls, a TextBlock for the data value and an Edit link.  I am trying to load the column's DataTemplate using XamlReader.Parse and the data value binding works correctly, but it looks like the ActionExecutionContext is not being setup properly in order for Message.Attach to work correctly.

 

Here's some sample code similar to what I'm trying to do:

 

 

            var templateColumn = new DataGridTemplateColumn { Header = "Template Column", IsReadOnly = true };
            var templateColumnDataTemplate = (DataTemplate)XamlReader.Parse(
                "<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:cal='clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro'>" + 
                    "<StackPanel Orientation=\"Horizontal\">" + 
                        "<TextBlock Text=\"{Binding DataValue}\" />" + 
                        "<TextBlock Text=\"edit\" Foreground=\"Blue\" Padding=\"5,0,0,0\" Cursor=\"Hand\" cal:Message.Attach=\"[Event MouseLeftButtonUp] = [Action EditDataValue(CompanyID)]\" />" + 
                    "</StackPanel>" + 
                "</DataTemplate>"
                );

            templateColumn.CellTemplate = templateColumnDataTemplate;
            MyDataGrid.Columns.Add(templateColumn);

 

 

 

The ActionExecutionContext has the Message and Source set, but everything else is null.  Any ideas?  Thanks!

Coordinator
Dec 7, 2010 at 1:01 PM

Can you send me a simple repro? Send to robertheisenberg at hotmail dot com

Dec 7, 2010 at 5:18 PM

False alarm, stupid mistake on my end.  The action method (EditDataValue in the example above) was marked as private, so Message.GetHandler wasn't finding it, which caused the issues I was seeing later on.

Coordinator
Dec 7, 2010 at 5:23 PM

Thanks for the update :)