Pregunta

Tengo este LonglistSelector vinculado a ObserverableCollection

<DataTemplate x:Key="ucItems" >
     <Grid Margin="0,0,0,17">
          <TextBlock Text="{Binding Title}" TextWrapping="Wrap" 
                     Style="{StaticResource MyBigBoldPhoneTextStyle}" />
     </Grid>
</DataTemplate>

y

<toolkit:LongListSelector x:Name="ucLongList" IsFlatList="True" 
     ItemsSource="{Binding UcItem}" 
     ItemTemplate="{StaticResource ucItems}" 
     ListHeaderTemplate="{StaticResource ucHeader}" 
     SelectionChanged="ListBox_SelectionChanged" />

UCitem tiene 3 propiedades que son: Título, ImageUri, Link

Necesito que la propiedad seleccionada-Ucitem-Link la pase a otros métodos. ¿Cómo puedo hacer eso?

Soy nuevo en LongListSelector y solía obtener una propiedad seleccionada de SelectedIndex de ListBox. Y no hay SelectedIndex en LongListSelector, por lo que tengo que usar SelectedItem para obtener la propiedad única.

por favor ayuda gracias.

¿Fue útil?

Solución

Aquí está el XAML para DataTemplate

<DataTemplate x:Key="ucItems" >
    <Grid Margin="0,0,0,17">
        <TextBlock Text="{Binding Title}" TextWrapping="Wrap"
                   Tag="{Binding}"
                   Style="{StaticResource MyBigBoldPhoneTextStyle}" />
    </Grid>
</DataTemplate>

Ahora para CodeBehind. Cuando está paseando a través de SelectedItems

var tbSender = (TextBlock)sender;
var theReference = (UcItem)tbSender.Tag;
Messagebox.Show(theReference.Link);

Así que de esa manera el Etiqueta El atributo se referirá a la instancia de UCitem.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top