2

I use c# .NET 4.5 and WPF RadControls from Telerik.

On my MainWindow I have a RadTabControl and in my code behind I bind my MainViewModel like this:

 this.DataContext = new MainViewmodel();

The ItemSource of the RadTabControl is bound in XAML:

 <telerik:RadTabControl ... ItemsSourc={Binding Tabs} .. />

I also use a ContentSelector to load different Contents to my Tabs. These Contents are UserControls. On one UserControl I use a RadGRidView with it's own ItemsSource that I bind in the code behind:

TestGridView.ItemsSource = Tasks.GetTasks();

The RadGridView Columns bound to it's own style:

 <telerik:RadGridView.Columns>
   <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Width="*" CellStyle="{StaticResource CellStyle}" />
 </telerik:RadGridView.Columns>

  <Style x:Key="CellStyle" TargetType="{x:Type telerik:GridViewCell}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border BorderBrush="#f2f2f2" BorderThickness="0,0,0,2" Padding="0,5,0,5">
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Top">
                                <TextBlock Text="{Binding Titel}" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Start}" Foreground="#9fa2ae"/>
                                    <TextBlock Text=" XXX - XXX " />
                                    <TextBlock Text="{Binding Startzeit}" Foreground="#9fa2ae" />
                                    <telerik:RadButton Height="30" Content="Right Button" Command="{Binding AddTabCommand}" CommandParameter="Tab9999"/>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

The Problem is that the RadButton does not fire the DelegateCommand of my MainViewModel. I have also the same Button in the UserControl out of the RadGridView, this works fine.

Please can somebody tell me how I can fix this problem of my RadButton in the RadGridView?

Thanks a lot Best Regards RR

PS: I have a simple project, but can't attach it

Ɖiamond ǤeezeƦ
  • 3,223
  • 3
  • 28
  • 40

2 Answers2

0

The reason why this is happening is that the binding on your RadButton is trying to find the AddTabCommand on the DataContext of the button, not the parent Window.

To fix this, I would advise setting the style inside the Window's resources, and instead of using this:

Command="{Binding AddTabCommand}"

Give the Window a name, and use this:

Command="{Binding ElementName=windowName, Path=DataContext.AddTabCommand}"
Mike Eason
  • 9,525
  • 2
  • 38
  • 63
0

Agree with what Mike said its not finding AddTabCommand in your DataContext(ViewModel). You can try with specifying whole path of the command :

Command="{Binding ElementName=windowName, Path=NameSapce_Name.ViewModelName.AddTabCommand}".