This project is read-only.

Change controls context

Jan 17, 2011 at 12:35 PM

Hi,

I have a DataGrid with a RowDetailsTemplate. It has a couple of fields and a button which executes a Command in my ViewModel. The problem is that it doesn't do it :/

I gues I have to change the controls context. Any suggestion?

Jan 17, 2011 at 12:45 PM

Use nRoute's command relays, see the following for more info / example:

http://www.orktane.com/Blog/post/2009/10/10/Introducing-nRouteToolkit-for-Silverlight-(Part-II).aspx

http://www.orktane.com/Blog/post/2009/11/03/I-Command-MVVM.aspx

Rishi

Jan 17, 2011 at 1:07 PM

I have something like this:

xmlns:n="http://nRoute/schemas/2010/xaml"
...
<UserControl.Resources>
        <n:CommandRelay x:Key="ZapiszPromocjeRelay"/>
    </UserControl.Resources>
...
<i:Interaction.Behaviors>
        <n:BridgeViewModelBehavior/>
        <n:BridgeCommandBehavior
            CommandRelay="{StaticResource ZapiszPromocjeRelay}"
            CommandSourceBinding="{Binding ZapiszPromocjeRelay, Mode=OneWay}"/>
    </i:Interaction.Behaviors>

And Visual Studio claims that it cannot find: CommandSourceBinding in BridgeCommandBehavior :/

Jan 17, 2011 at 1:14 PM

Well, unless you are using WP7 you woun't find the CommandSourceBinding property anymore since SL4 now supports inline binding. So basically if you are using SL4/WPF just change CommandSourceBinding to CommandSource, and it should work. The binding post-fixed properties are a work-around for binding shortcomings in SL3.

Cheers,
Rishi 

Jan 17, 2011 at 1:31 PM

One more thing, your CommandSource shouldn't be the relay itself - in most likelihood, you should be getting your CommandSource from your VM - so bind to that, binding to the relay itself doesn't make sense. Relays basically front ICommands, so they need to be sourced from somewhere else.

Rishi

Jan 17, 2011 at 1:33 PM
Edited Jan 17, 2011 at 1:48 PM

I don't understand what you are talking about :(

Now it works great, earlier when I've bound in my button to an AcctionCommand in my VM it didn't work beacause the Button is inside a RowDetailsTemplate of a DataGrid

Jan 17, 2011 at 4:57 PM

I was talking about this part of your xaml:

<n:BridgeCommandBehavior
            CommandRelay="{StaticResource ZapiszPromocjeRelay}"
            CommandSourceBinding="{Binding ZapiszPromocjeRelay, Mode=OneWay}"/>

See the CommandRelay and CommandSourceBinding both bind to ZapiszPromocjeRelay - that is wrong.

Rishi

Jan 17, 2011 at 5:10 PM

I've noticed that and fixed that line and thats why I said it's working great :)