I have the following RadDataGRid which is bound to a collection ('DisplayItems') of an abstract class 'AgendaItem' which can show different types of inherited objects and one of these is called a VoteAgendaItem which needs to pop up a flyout on selection (see bottom of XAML). The problem is that I also need to have a SelectionChanged event handler to control various aspects of the grid but as soon as I added the handler it stopped the Vote flyout from happening (as the handler has now obviously handled the event) so how can I both handle the selection event but allow a VoteAgendaItem instance to be shown in the flyout?
<Grid:RadDataGrid x:Name="agendaDataGrid"
Margin="48,0,48,24"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{x:Bind ViewModel.DisplayItems, Mode=OneWay}"
UserGroupMode="Disabled"
UserFilterMode="Disabled"
UserColumnReorderMode="None"
UserSortMode="None"
AutoGenerateColumns="False"
GridLinesVisibility="Horizontal"
BorderBrush="Transparent"
BorderThickness="0"
SelectionChanged="AgendaDataGrid_SelectionChanged"
SelectedItem="{x:Bind ViewModel.SelectedAgendaItem, Mode=TwoWay}"
LayoutUpdated="OnLayoutUpdated">
<Grid:RadDataGrid.Columns>
<!-- Read state of item -->
<Grid:DataGridTemplateColumn SizeMode="Auto"
CellDecorationStyleSelector="{StaticResource BackgroundSelector}"
CellContentTemplateSelector="{StaticResource ReadStateItemTemplateSelector}">
<Grid:DataGridTemplateColumn.Header>
<Border CornerRadius="45"
Background="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}"
Height="10"
Width="10"
HorizontalAlignment="Center" />
</Grid:DataGridTemplateColumn.Header>
</Grid:DataGridTemplateColumn>
<!-- Item position -->
<Grid:DataGridNumericalColumn Header="#"
PropertyName="PositionString"
SizeMode="Auto"
CellDecorationStyleSelector="{StaticResource BackgroundSelector}"/>
<!-- Download status -->
<Grid:DataGridTemplateColumn SizeMode="Auto"
CellContentTemplateSelector="{StaticResource DownloadAgendaItemTemplateSelector}"
CellDecorationStyleSelector="{StaticResource BackgroundSelector}">
<Grid:DataGridTemplateColumn.Header>
<TextBlock FontFamily="{ThemeResource SymbolThemeFontFamily}"
Text="" />
</Grid:DataGridTemplateColumn.Header>
</Grid:DataGridTemplateColumn>
<!-- Item name -->
<Grid:DataGridTextColumn x:Name="ItemNameColumn"
Header="Item name"
PropertyName="Name"
SizeMode="Stretch"
CellDecorationStyleSelector="{StaticResource BackgroundSelector}"
/>
<!-- other grid columns not shown -->
</Grid:RadDataGrid.Columns>
<!-- Flyout for VoteAgendaItem which should show when item is selected -->
<FlyoutBase.AttachedFlyout>
<Flyout Placement="Full"
FlyoutPresenterStyle="{StaticResource VoteFlyoutPresenterStyle}">
<Grid Width="430">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap"
Text="{x:Bind ViewModel.SelectedVoteItem.VoteTitle, Mode=OneWay}" />
<TextBlock TextWrapping="Wrap"
Text="{x:Bind ViewModel.SelectedVoteItem.VoteDescription, Mode=OneWay}"
Grid.Row="1" />
<ListView Grid.Row="3"
ItemsSource="{x:Bind ViewModel.SelectedVoteItem.VoteOptions, Mode=OneWay}"
ScrollViewer.VerticalScrollBarVisibility="Disabled" />
</Grid>
</Flyout>
</FlyoutBase.AttachedFlyout>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior ComparisonCondition="NotEqual"
Binding="{x:Bind ViewModel.SelectedVoteItem, Mode=OneWay}">
<components:OpenFlyoutAction TargetObject="{x:Bind agendaDataGrid, Mode=OneWay}" />
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Grid:RadDataGrid>
//We need this here to prevent a disabled or downloading item (row) from being selectable.
//Also if the selected row is a header then call the ViewModel method to add or remove sub items.
private async void AgendaDataGrid_SelectionChanged(object sender, DataGridSelectionChangedEventArgs e)
{
//NOTE: DataGrid is in single selection mode. If using multiple selection, you need to iterate over e.AddedItems.
if (e?.AddedItems?.FirstOrDefault() is AgendaItem selectedItem)
{
if (selectedItem.IsDownloading)
{
//The item is still downloading so do not let it be selected.
agendaDataGrid.SelectedItems.Remove(selectedItem);
}
else if (!selectedItem.Enabled)
{
//User does not have permission to view item
//TODO: If we don't need this message then add check to the IsDownloading check above
await Dialogs.ShowMessage("You do not have permission to view the selected agenda item");
}
else if (selectedItem is HeaderAgendaItem)
{
//The item is a header so call VM method to add or remove sub items as necessary.
ViewModel.UpdateSubItemsForHeader(selectedItem as HeaderAgendaItem);
}
}
}