This question is locked. New answers and comments are not allowed.
Hello,
I´m trying to get the selected item of a databound Silverlight ListBox. My databinding is working very well, all the data are appearing on the screen. The problem is to retrieve the selected item through RadContextMenu. In the Opening event, this is the code:
But the "item" variable ever returns null. I´ve already checked my data source and it´s all ok, all the data is being returned. I´ve also changed to RadDataBoundListBox and the behavior is the same.
Here is my xaml code under a ListBox silverlight:
Am I doing something wrong and the selection doesn´t works?
Thanks in advance,
Thiago
I´m trying to get the selected item of a databound Silverlight ListBox. My databinding is working very well, all the data are appearing on the screen. The problem is to retrieve the selected item through RadContextMenu. In the Opening event, this is the code:
var selectedItem;ListBoxItem item = e.FocusedElement as ListBoxItem;selectedItem = item.DataContext as MyObjectModel;Here is my xaml code under a ListBox silverlight:
<ListBox ItemsSource="{Binding LstAlimentos}" Margin="0,20,0,0" Name="ltbAlimentos"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="50" /> <RowDefinition Height="50" /> <RowDefinition Height="50" /> </Grid.RowDefinitions> <TextBlock Width="600" Height="50" HorizontalAlignment="Left" TextAlignment="Left" Margin="0,0,0,0" Text="{Binding Nome}" FontFamily="Segoe WP" FontWeight="Bold" FontSize="25" Grid.Row="0" Foreground="{Binding Favorito, Converter={StaticResource BoolToBrushConverter}}"/> <TextBlock Width="300" Height="50" HorizontalAlignment="Left" TextAlignment="Left" Margin="0,-30,0,0" Text="{Binding Quantidade}" FontFamily="{StaticResource PhoneFontFamilyLight}" FontSize="25" Grid.Column="1" Grid.Row="1" Foreground="{Binding Favorito, Converter={StaticResource BoolToBrushConverter}}"/> <TextBlock Width="160" Height="50" HorizontalAlignment="Left" TextAlignment="Left" Margin="-8,-50,0,0" Text="{Binding Pontos, StringFormat=' {0} pontos'}" FontFamily="{StaticResource PhoneFontFamilyLight}" FontSize="25" Grid.Column="2" Grid.Row="2" Foreground="{Binding Favorito, Converter={StaticResource BoolToBrushConverter}}" /> <telerikPrimitives:RadContextMenu.ContextMenu> <telerikPrimitives:RadContextMenu OpenGesture="Hold" x:Name="ctmOpcoes" Opening="ctmOpcoes_Opening"> <telerikPrimitives:RadContextMenuItem Content="adicionar" Name="mnuAdicionar" Tap="mnuAdicionar_Tap" Visibility="{Binding Favorito, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Adicionar'}"/> <telerikPrimitives:RadContextMenuItem Content="excluir" Name="mnuExcluir" Tap="mnuExcluir_Tap" Visibility="{Binding Favorito, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter='Excluir'}" /> </telerikPrimitives:RadContextMenu> </telerikPrimitives:RadContextMenu.ContextMenu> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox>Am I doing something wrong and the selection doesn´t works?
Thanks in advance,
Thiago