This question is locked. New answers and comments are not allowed.
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
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