简体   繁体   中英

C# Windows Phone 8.1 specific Navigation in Listview

Hello i'm new in programming and i making a Football Windows Phone 8.1 Application using Web Services. i created a class Football.cs:

    public int Id { get; set; }
    public string Team1 { get; set; }
    public string Team2 { get; set; }
    public string Score { get; set; }
    public string Place { get; set; }
    public string Stadium { get; set; }

Then i generated a Web API 2 Controller using Entity Framework to create the DataBase and get the data from it. Then i created a Windows Phone application, in the Mainpage.xaml here's the code :

<Page.Resources>
    <DataTemplate x:Key="EmployeeDataTemplate">
        <Grid Margin="12,12,12,0"
            Width="376">
            <TextBlock 
                FontSize="24" 
                Text="{Binding Team1}"/>
            <TextBlock 
                FontSize="24"
                HorizontalAlignment="Right" 
                Text="{Binding Team2}"/>
            <StackPanel>
                <TextBlock 
                    FontSize="18.667"
                    HorizontalAlignment="Center"
                    Text="{Binding Score}" />
            </StackPanel>
        </Grid>
    </DataTemplate>
</Page.Resources>

<Page.DataContext>
    <Core:MainViewModel/>
</Page.DataContext>

<Grid>
    <ListView x:Name="mainListView"
              ItemsSource="{Binding EmployeesList}"
              ItemTemplate="{StaticResource EmployeeDataTemplate}" 
              IsItemClickEnabled="True" 
              ItemClick="listView_ItemClick"/>
</Grid>

then i created a new BasicPage.xaml:

<Page.DataContext>
    <Core:MainViewModel/>
</Page.DataContext>

<StackPanel>
    <TextBlock Text="{Binding Place}" />
    <TextBlock Text="{Binding Stadium}"/>
</StackPanel>

Can you help me please, i'm a beginner and i tried to make it but without success. All i want is when i click in a specific Item in the ListView, the Basic Page will display the Place and the Stadium to ONLY and ONLY to this specific Item , not the first one and not all of them. Thank you very much, i appreciate it

See my answer here , I use the Behaviours Sdk(how to add) in conjunction with a custom converter class to receive the tapped item in the list. I believe this is what you are looking for.

If you are using MVVM Light you can do this with generic RelayCommand<T> like this:

<ListView x:Name="mainListView"
          ItemsSource="{Binding EmployeesList}"
          ItemTemplate="{StaticResource EmployeeDataTemplate}" 
          IsItemClickEnabled="True" 
          Command={Binding ShowMathInfo, Source={StaticResource MainViewModel}}"
          CommandParameter="{Binding }"/>

Then in your command execute method you will get item what you clicked on, then you will be able to pass this item to another page or what you need to do with it.

there's no propertie called Command under ListView. or maybe it's not like this ? am i wrong ? sorry but i'm a really beginner

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