Windows Phone 8.1获取自定义ListView项的值

时间:2015-02-27 09:44:14

标签: c# listview windows-phone-8.1 windows-phone

我有一个ListViewItems的DataTemplate:

<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>

对于我的ListView:

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

并在运行时创建项目列表:

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] });
          }  
     }

班级系统是:

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

如何在systemlist_SelectionChange事件中获取所选项目的三个属性?:

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

1 个答案:

答案 0 :(得分:0)

最后在windowsapptutorials

中找到了解决方案

可以将所选项目转换为fissystem:

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