Handling Button click inside RadJumpList

2 posts, 0 answers
  1. Danny
    Danny avatar
    11 posts
    Member since:
    Sep 2013

    Posted 31 Jan 2015 Link to this post

    Hi,

    What is the correct way to handle a button click event inside a RadJumpList? I am currently walking the control tree to get the object attached to the RadJumpList row that I need. Is this the correct way to do it or is there a better way?

    <telerikData:RadJumpList x:Name="rjlSchedule" Grid.Row="3" Margin="30,10,30,10" IsSynchronizedWithCurrentItem="True">
                            <telerikData:RadJumpList.ItemTemplate>
                                <DataTemplate>
                                    <Grid x:Name="gridInviteToGroup">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="auto"/>
                                            <RowDefinition Height="auto"/>
                                            <RowDefinition Height="auto"/>
                                            <RowDefinition Height="auto"/>
                                            <RowDefinition Height="auto"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock x:Name="tbGroupName" Grid.Row="0" Grid.Column="0" Text="{Binding Group.GroupName}" />
                                        <TextBlock x:Name="tbMemberCount" Grid.Row="1" Grid.Column="0" Text="{Binding Path=Group.GroupMembers.Count, StringFormat='Members: \{0\}'}" />
                                        <TextBlock x:Name="tbGroupCourseName" Grid.Row="2" Grid.Column="0" Text="{Binding Course.CourseName}" TextWrapping="Wrap" />
                                        <TextBlock x:Name="tbGroupDate" Grid.Row="3" Grid.Column="0" Text="{Binding Date, StringFormat='\{0:D\}'}" />
                                        <TextBlock x:Name="tbGroupAMPM" Grid.Row="4" Grid.Column="0" Text="{Binding RoundAMPM}" />
                                        <Button x:Name="btnInviteToGroup" Grid.RowSpan="5" Grid.Column="1" VerticalAlignment="Center" Content="invite" HorizontalAlignment="Right" Click="btnInviteToGroup_Click" />
                                    </Grid>
                                </DataTemplate>
                            </telerikData:RadJumpList.ItemTemplate>
                        </telerikData:RadJumpList>

    private void btnInviteToGroup_Click(object sender, RoutedEventArgs e)
            {
                Button buttonSender = sender as Button;
                // Get the buttons parent container
                DependencyObject grid = VisualTreeHelper.GetParent(buttonSender);
                // Get the grids parent container
                DependencyObject contentPresenter = VisualTreeHelper.GetParent(grid);
                // Convert to a content presenter
                ContentPresenter selectedItem = (ContentPresenter)contentPresenter;
                // Get the schedule object
                Schedule sch = (Schedule)selectedItem.Content;

                // Show confirm message
                string message = "Invite " + playerName + " to join group " + sch.Group.GroupName + "?";
                MessageBoxResult confirm = MessageBox.Show(message, "Invite Player", MessageBoxButton.OKCancel);

                if (confirm == MessageBoxResult.OK)
                {
                    // Do something
                }
            }

    Thanks
    Danny
  2. Dimitrina
    Admin
    Dimitrina avatar
    442 posts

    Posted 04 Feb 2015 Link to this post

    Hi Danny,

    You can use the button's DataContext to get the object you need.

    I hope this helps. Please, let us know if you have further questions.

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
Back to Top