简体   繁体   中英

Windows Phone 8.1 Get Values of Custom ListView Item

I Have a DataTemplate for ListViewItems:

<DataTemplate x:Key="GroupTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,9.5,0,0">
                <Image Source="{Binding Property3}" Height="79" Width="79"/>
            </Border>
            <StackPanel Grid.Column="1" Margin="14.5,0,0,0">
                <TextBlock Text="{Binding Property1}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                <TextBlock Text="{Binding Property2}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
            </StackPanel>
        </Grid>
    </DataTemplate>

For my ListView:

 <ListView Grid.Row="2" x:Name="systemlist" ItemTemplate="{StaticResource GroupTemplate}"  Margin="19,12,19,0" SelectionChanged="systemlist_SelectionChanged"/>

and create a List of Items on runtime:

List<fissystem> items = new List<fissystem>();
for (int i = 0; i < systems.Length; i++)
     {
          string[] parts = systems[i].Split(';');
          if (parts.Length == 3)
          {
              items.Add(new fissystem() { Property1 = parts[0], Property2 = parts[1], Property3 = parts[2] });
          }  
     }

The class fissystem is:

public class fissystem
    {
        public string Property1 { get; set; }
        public string Property2 { get; set; }
        public string Property3 { get; set; }
    }

How can i get the three Propertys of a selected Item in the systemlist_SelectionChange event?:

private void systemlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // Add this code.
    }

Finally found a solution in windowsapptutorials

It is possible to cast the selected Item to fissystem:

private void systemlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    fissystem item = (sender as ListView).SelectedItem as fissystem;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM