Commands in datatemplate

3 posts, 1 answers
  1. Dom
    Dom avatar
    18 posts
    Member since:
    May 2011

    Posted 28 Oct 2011 Link to this post

    Hi,

    I have a list of tabs (binding on a collection)
    in each tab I have a control with a command.
    Problem is command doesn't seem to work, it never launches.

    Here's a simple examble that works :


           <telerik:RadTabControl >
                                    <telerik:RadTabItem Header="Test">
                                        <Button Content="Test" Command="{Binding CharacteristicMenu}" CommandParameter="Add" />
                                    </telerik:RadTabItem>
                                </telerik:RadTabControl>

    and here's one close to what I want to do that doesn't work :

      <telerik:RadTabControl ItemsSource="{Binding Tabs}">
                                    <telerik:RadTabControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel>
                                                <TextBlock Text="{Binding Path=Name.Text, Mode=TwoWay}" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </telerik:RadTabControl.ItemTemplate>
                                    <telerik:RadTabControl.ContentTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <StackPanel>
                                                    <Button Content="Test" Command="{Binding CharacteristicMenu}" CommandParameter="Add" />
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </telerik:RadTabControl.ContentTemplate>
        </telerik:RadTabControl>

    I can't seem to make the commands works inside a datatemplate. I need to get commands to work with a button and with your contextuelmenu.
    Is it a limitation of the tabcontrol or something? I tried a radbutton instead of button with no success (which wouldn't of fixed the problem with a contextuelmenu anyway).

    Thanks
    Dom
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 02 Nov 2011 Link to this post

    Hi Dom,

    I wasn't able to reproduce this issue on our side. It might be related to the structure of your view models and the business data. I prepared a sample project - please have a look at it and let me know if it works for you or if I'm missing something.

    Greetings,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Dom
    Dom avatar
    18 posts
    Member since:
    May 2011

    Posted 04 Nov 2011 Link to this post

    Tried your project, seems to be what I want, i added the docking around it, and it still works.

    I compared yours to mine, and problem seems to be that I put the command/Delegate in the mainviewmodel (didn't have a view model for each tabs, just had the data for each to bind).

    It seems to be the problem so I'll try changing that.
Back to Top