我的名单怎么没出现?

时间:2015-02-06 17:16:32

标签: c# linq xaml windows-phone-7

我正在开发一个Windows手机应用程序,我需要显示一个页面作为登录人员的Coletors列表,但它没有显示在页面中,我不知道为什么。我尝试以不同的方式编写代码,但它仍然不起作用。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Data.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace Aplicativo_Windows_Phone
{
    public partial class ColetoresPage : PhoneApplicationPage, INotifyPropertyChanged
    {
        AppDataContext db;
        string email;
        public ColetoresPage()
        {
            InitializeComponent();

            db = new AppDataContext();

            List<HyperlinkButton> listaLinks = new List<HyperlinkButton>();

            int i=0;

            foreach (var pessoa in db.Pessoas)
            {
                if (pessoa.Email == email)
                {
                    foreach (var coletor in pessoa.Coletores)
                    {
                        HyperlinkButton aux = new HyperlinkButton();
                        aux.Content = "Coletor " + (i + 1).ToString();
                        aux.FontSize = 24;
                        aux.NavigateUri = new Uri("/OcorrenciasPage.xaml?coletorId=" + coletor.Id, UriKind.RelativeOrAbsolute);
                        listaLinks.Add(aux);
                        i++;
                    }
                }
            }

            ListBox coletores = new ListBox();
            coletores.ItemsSource = listaLinks;
            stcList.Children.Add(coletores);
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            NavigationContext.QueryString.TryGetValue("email", out email);
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void btnAdd_Click_1(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/AddColetor.xaml?email=" + email, UriKind.RelativeOrAbsolute));
        }
    }
}

Tha xaml代码:

<phone:PhoneApplicationPage
    x:Class="Aplicativo_Windows_Phone.ColetoresPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="coletores" Margin="9,-7,167,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="80"/>
                </Grid.RowDefinitions>
                <StackPanel Grid.Row="0" Name="stcList">

                </StackPanel>
                <Button Name="btnAdd" Content="Adicionar" Click="btnAdd_Click_1" Grid.Row="1"/>
            </Grid>
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

0 个答案:

没有答案