DataGrid TemplatedColumn with button doesn't pass a DependencyParameter

Jan 20, 2011 at 9:14 AM


I have a standard data grid form the SL Toolkit. It has two columns and one is templated. The template looks like this:

<i:EventTrigger EventName="Click">
<n:ExecuteCommandAction Command="{Binding EdycjaWarunku,
Source={StaticResource ViewModel}}">
Value="{Binding ElementName=warunkiPromocjiGrid, Path=SelectedItem}"/>

The method in my ViewModel executes fine but no Dependency Parameter is passed. When I take the Button code and place it outside the grid column it works fine. Any suggestions on that?


Jan 20, 2011 at 12:50 PM

The problem is same is I mentioned earlier, you can't access an instantiated member (in the Visual-Tree) from the DataTemplate directly - think of a DataTemplate as being a type definition (ie. var _x = typeof(Foo)), and a type definition cannot access an instantiated instance (i.e. var _y = new Foo()) directly. This is the reason we have value relays - they act like static members  (e.g. var _z = Foo.Message), which you can access without instantiating an instance using StaticResource binding.

Also FYI, in most cases you can bind directly to the CommandParameter without having to use a DependencyParameter, eg:

<i:EventTrigger EventName="Click">
n:ExecuteCommandAction Command="{Binding EdycjaWarunku, Source={StaticResource ViewModel}}" Parameter="{Binding Value}" />

Hope this helps,

Jan 20, 2011 at 1:13 PM
Edited Jan 20, 2011 at 1:27 PM

Ok, so what would you suggest to do? Becuase I can't find any example with value relay for nRoute.

Jan 20, 2011 at 10:47 PM

Value Relay Info:

Value Relay Sample: (more in repository)


Jan 21, 2011 at 7:39 AM

Hmm... I've declared the ValueRelay:

<n:ValueRelay x:Key="WarunekPromocjiValueRelay"/>

Also the ExecuteCommand:

<n:ExecuteCommandAction Command="{Binding EdycjaWarunku, Source={StaticResource ViewModel}}" Parameter="{Binding Value, Source={StaticResource WarunekPromocjiValueRelay}, Mode=TwoWay}"/>

But I don't get the code behind part of it. To what should I hook up? The the buttons load event and there set the value for the parameter?

Jan 21, 2011 at 12:28 PM

I did something like this:

private void Button_Loaded(object sender, RoutedEventArgs e)
(sender as Button).DataContext as WebApplication2.WarunkiPromocji);

But the problem is that all the buttons have the same datacontext. Every button should have the context of the it's placed in. Any suggestions?

Jan 31, 2011 at 10:50 AM

Here, I've created a small sample showing how to use a command from a cell-template:

Hope this helps,