Windows phone 7 可在emulator中调试和不调试,但只能在设备上调试

Windows phone 7 可在emulator中调试和不调试,但只能在设备上调试,windows-phone-7,Windows Phone 7,我正在为WP7开发一个应用程序,但我遇到了一个以前从未见过的问题。当我在emulator中构建并运行它时,它在debug和no debug ctrl-F5中都能正常工作。但是在Windows设备上,它只在调试F5中工作。当我在设备上运行它而不调试ctrl-F5时,应用程序启动,但当我点击按钮时,它只会退出应用程序。在单击按钮时,我加载了一个xml文件。xml文件设置为生成操作内容,复制到输出不复制。我做错什么了吗?我想知道加载的xaml文件中的以下代码是否与错误有关: <phone:Pho

我正在为WP7开发一个应用程序,但我遇到了一个以前从未见过的问题。当我在emulator中构建并运行它时,它在debug和no debug ctrl-F5中都能正常工作。但是在Windows设备上,它只在调试F5中工作。当我在设备上运行它而不调试ctrl-F5时,应用程序启动,但当我点击按钮时,它只会退出应用程序。在单击按钮时,我加载了一个xml文件。xml文件设置为生成操作内容,复制到输出不复制。我做错什么了吗?我想知道加载的xaml文件中的以下代码是否与错误有关:

<phone:PhoneApplicationPage 
x:Class="appname.NamesList"
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"
xmlns:local="clr-namespace:appname"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">

<phone:PhoneApplicationPage.DataContext>
    <local:MainViewModel />
</phone:PhoneApplicationPage.DataContext>

<Grid x:Name="LayoutRoot"
      Background="Transparent">
    <toolkit:LongListSelector ItemsSource="{Binding Persons}">
        <toolkit:LongListSelector.GroupItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </toolkit:LongListSelector.GroupItemsPanel>
        <toolkit:LongListSelector.GroupHeaderTemplate>
            <DataTemplate>
                <Border Background="Transparent">
                    <Border Width="75"
                            Height="75"
                            HorizontalAlignment="Left"
                            Background="{StaticResource PhoneAccentBrush}">
                        <TextBlock VerticalAlignment="Bottom"
                                   Foreground="{StaticResource PhoneForegroundBrush}"
                                   Style="{StaticResource PhoneTextExtraLargeStyle}"
                                   Text="{Binding Key}" />
                    </Border>
                </Border>
            </DataTemplate>
        </toolkit:LongListSelector.GroupHeaderTemplate>
        <toolkit:LongListSelector.GroupItemTemplate>
            <DataTemplate>
                <Border Width="75"
                        Height="75"
                        Background="{StaticResource PhoneAccentBrush}"
                        IsHitTestVisible="{Binding HasItems}">
                    <TextBlock VerticalAlignment="Bottom"
                               Margin="{StaticResource PhoneTouchTargetOverhang}"
                               FontFamily="{StaticResource PhoneFontFamilySemiBold}"
                               FontSize="{StaticResource PhoneFontSizeExtraLarge}"
                               Foreground="{StaticResource PhoneForegroundBrush}"
                               Text="{Binding Key}" />
                </Border>
            </DataTemplate>
        </toolkit:LongListSelector.GroupItemTemplate>
        <toolkit:LongListSelector.ItemTemplate>
            <DataTemplate>
                <Grid Margin="{StaticResource PhoneTouchTargetOverhang}">
                    <HyperlinkButton Name="cmdName" 
                                     Content="{Binding Name}"
                                     Click="cmdName_Click"
                                     Margin="75,0,0,0" 
                                     HorizontalAlignment="Left"
                                     FontSize="40" />
                </Grid>
            </DataTemplate>
        </toolkit:LongListSelector.ItemTemplate>
    </toolkit:LongListSelector>

</Grid>
以及MainViewModel:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using appname.Helpers;

namespace appname
{
    public class MainViewModel
    {
        public MainViewModel()
        {
            App app = Application.Current as App;

            XmlHelper xmlHelper = new XmlHelper();
            app.persons = xmlHelper.GetPersons(app.gender);
            List<Person> persons = app.persons;


            this.Persons = new LongListCollection<Person,char>(persons, person => person.Name[0]);
        }

        public LongListCollection<Person, char> Persons
        {
            get;
            private set;
        }
    }
}
编辑 读取xml文件的代码如下:

 public List<Person> GetPersons(string gender)
    {
        string xmlPath = "";
        if (gender == "Boys")
            xmlPath = @"Resources/Boys/Xml/Names.xml";
        else if( gender == "Girls" )
            xmlPath = @"Resources/Girls/Xml/Names.xml";

        //Uri uri = new Uri(xmlPath, UriKind.Relative);
        StreamResourceInfo sm = Application.GetResourceStream(new Uri(xmlPath, UriKind.Relative));
        System.Xml.XmlReader xr = System.Xml.XmlReader.Create(sm.Stream);

        XDocument data = XDocument.Load(xr);



        return (from c in data.Descendants("Person")
                orderby c.Attribute("Name")
                select new Person()
                {
                    Name = c.Element("Name").Value,
                    Description = c.Element("Description").Value,
                    ...
                    HasGraph = c.Element("HasGraph").Value
                }).ToList();
    }
编辑


你发布的代码没有问题。我们需要查看XmlHelper类的代码,以提供详细信息

但是,我怀疑您以错误的方式处理资源管理。另外,我建议您尝试将代码包装在try/catch中,然后使用MessageBox.ShowwiththeException消息

这至少应该确保崩溃是否与异常相关

public MainViewModel()
{
    try
    {
        App app = Application.Current as App;

        XmlHelper xmlHelper = new XmlHelper();
        app.persons = xmlHelper.GetPersons(app.gender);
        List<Person> persons = app.persons;


        this.Persons = new LongListCollection<Person,char>(persons, person => person.Name[0]);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
}
我的天啊

我尝试在我的手机上启动另一个应用程序,它也退出了。所以,我重新启动了手机,我想我昨天已经这么做了,它工作了!很抱歉浪费了你的时间


他是个尴尬的傻瓜

添加了try-catch,但在应用退出时不显示。在文章中还添加了xml代码。那么退出与MainViewModel中的任何代码都不相关。在重新部署应用程序之前,是否已将其完全卸载到设备上?是。现在尝试了,奇怪,因为现在列表已加载,当我单击A,然后单击N random时,它退出。下次我启动它时,它会在加载列表之前退出。昨天晚上也发生了同样的事情。奇怪的也许是不好的依赖关系?您正在使用哪个版本的Silverlight Toolkit?是否可以尝试添加MessageBox。在App.cs文件中的应用程序\u UnhandledException处理程序中显示?如果您有足够的声誉,您可以删除自己的问题。如果可能的话,我建议你这样做。是的,克劳斯,但我得等两天才能删除它。谢谢你的帮助!
public MainViewModel()
{
    try
    {
        App app = Application.Current as App;

        XmlHelper xmlHelper = new XmlHelper();
        app.persons = xmlHelper.GetPersons(app.gender);
        List<Person> persons = app.persons;


        this.Persons = new LongListCollection<Person,char>(persons, person => person.Name[0]);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
}