Question

i have this LongListSelector bound to observerableCollection

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

and

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

UcItem has 3 property which are: Title, ImageUri, Link

I need to get the selected-ucItem-Link property to pass it to other methods. how can i do that?

Im new to LongListSelector and i used to get a selected property from SelectedIndex from listbox. And there is no selectedIndex in LongListSelector so i have to use SelectedItem to get the single property on it.

please help thanks.

Was it helpful?

Solution

Here's the xaml for DateTemplate

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

Now for codebehind. When you are looping through the selecteditems

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

So that way the Tag attribute will reference to the instance of UcItem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top