I'm having a challenge getting the commanding to work (MVVM approach) with a Button inside the RadGridView.
My column is as follows:
<telerikGridView:GridViewDataColumn Width="50" >
<telerikGridView:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Button x:Name="EditButton" Command="{Binding Path=LayoutRoot, Path=DataContext.EditRecordCommand}" Content="Edit" Width="40" Height="20" FontSize="11" FontWeight="Normal" MinWidth="1" />
</DataTemplate>
</telerikGridView:GridViewDataColumn.CellTemplate>
</telerikGridView:GridViewDataColumn>
My code however does not seem to execute.
Is this a known issue? I'm using the SL 4 version of the controls with VS2010.
Regards,
Chris
7 Answers, 1 is accepted
Your Command needs to be bound like this:
Command="{Binding Path=DataContext.EditRecordCommand, ElementName=LayoutRoot}"Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Sorry, I noticed I had retyped the ElementName and typed Path by mistake in my sample code below.
I had the same code as you and that did not work.
This is my code...
<telerikGridView:GridViewColumn Width="50" >
<telerikGridView:GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="EditButton" Command="{Binding Path=DataContext.EditRecordCommand, ElementName=LayoutRoot}" Content="Edit" Width="40" Height="20" FontSize="11" FontWeight="Normal" MinWidth="1" />
</DataTemplate>
</telerikGridView:GridViewColumn.CellTemplate>
</telerikGridView:GridViewColumn>
Regards,
Chris
If you define your ViewModel like this:
<UserControl.Resources> <my:MyViewModel x:Key="MyViewModel"/></UserControl.Resources><telerik:GridViewColumn Header="Actions"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <Button Command="{Binding SaveCommand, Source={StaticResource MyViewModel}}" CommandParameter="{Binding}">Save</Button> </DataTemplate> </telerik:GridViewColumn.CellTemplate> </telerik:GridViewColumn>All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Regards,
Chris
Instantiating the ViewModel as a resource does not preclude setting it as a DataContext in the page:
<UserControl ...DataContext="{StaticResource MyViewModel}">All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
In this case, you need to use a DataContextProxy.
All the best,
Yavor Georgiev
the Telerik team