Bind button command to source other than parent's datacontext
I am trying to bind the command of a button inside a datacontext to a RelayCommand in the Main viewmodel. When I use Blend it changes the datacontext of the contain开发者_运维知识库ing grid to point to the Main ViewModel thus breaking the binding of the content of the grid which should be based on the viewmodel of the row etc. I tried the following but the compiler says I am missing an attribute name.
<Button Style="{StaticResource StatusButtonStyle}">
<Button.Command>
<Binding Source="{StaticResource Locator" Path="{Main.ViewStatusCommand}" Mode="OneWay"
</Button.Command>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
I also tried this:
<Button Style="{StaticResource StatusButtonStyle}" Command="{Binding Main.ViewStatusCommand, Source=StaticResource Locator}">
But that doesn't work either. If I am not alowed to set the source of the command binding, could someone please explain why? Thanks.
You forgot some brackets in the second exemple (and the first lack a /> in the Binding element )
<Button Style={StaticResource StatusButtonStyle}" Command="{Binding Main.ViewStatusCommand, Source={StaticResource Locator}}">
Is it the reason explaining why it don't work? If it's not the case, could you please describe your symptoms (nothing happen when I push the button, there is an Exception (if this is the case, when, and what exception? ) )
If nothing happen when you push the button, look at the debugging console to retreive the Bindings errors.
精彩评论