开发者

How to bind the ItemSource inside the DataGrid to an element outside the DataContext, eg. ViewModel in Silverlight 4

I have a DataGrid with some text columns and a button. I want to bind button to a command on the ViewModel. Since, Columns are inside the context of the ItemSource, i want to change the DataContext for the button to something outside the DataGrid(to a view model, to access the Command) or else Silverlight is not able to find the binding expression for that command on the ItemSource context.

Here is what i am doing but i am unsuccessful in doing so. I am not sure where i am making a mistake

<DataGrid >
   ...     
   <Button>
           <i:Interaction.Triggers>
              <i:EventTrigger EventName="Click">
                 &开发者_如何学编程lt;i:InvokeCommandAction Command="{Binding Path=DataContext.CommandToCall, ElementName=DataGridName}" />
              </i:EventTrigger>
           </i:Interaction.Triggers>
     </Button>
   ...
</DataGrid>

I do not get any Binding error on doing this but i cannot invoke the command inside my ViewModel. Please note, it is for silverlight and not WPF. Thanks


I had this same problem recently. I was using a Telerik RadGridView, and I found a workaround on their support forum. Maybe you can do something similar.

Here's the question, and here's the workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜