This is a migrated thread and some comments may be shown as answers.

Handling Button click inside RadJumpList

1 Answer 27 Views
JumpList
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Danny
Top achievements
Rank 1
Danny asked on 31 Jan 2015, 03:11 PM
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

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 04 Feb 2015, 12:51 PM
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.

 
Tags
JumpList
Asked by
Danny
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or