简体   繁体   English

UWP应用,在this.Frame.Navigate上崩溃

[英]UWP app, crash on this.Frame.Navigate

I have a UWP app, with two Pages: MainPage and EventPage. 我有一个UWP应用,其中有两个页面:MainPage和EventPage。 On both of these there is a splitView, and at the top of this a GridView with two buttons - one to navigate to MainPage, and one to navigate to EventPage. 在这两个位置上都有一个splitView,在它的顶部是一个带有两个按钮的GridView-一个导航到MainPage,另一个导航到EventPage。 The XAML for the buttons looks like this: 按钮的XAML如下所示:

<Button Content="Browse by system" 
        HorizontalAlignment="Center" 
        Margin="0,0,0,0" 
        VerticalAlignment="Top"
        Width="250"
        Click="SystemButtonClick"/>

However, when i press the "Browse by system" button, the app crashes. 但是,当我按下“按系统浏览”按钮时,应用程序崩溃了。 Here is the constructor for the page: 这是页面的构造函数:

public EventPage()
    {
        this.InitializeComponent();
        var systemList = SystemClass.GetSystems();
        systemList.Sort();
        Systems = new ObservableCollection<string> (systemList);
    }

It passes the constructor fine, and instead crashes when exiting the eventhandler for the button click: 它可以很好地通过构造函数,而在退出按钮单击的事件处理程序时崩溃:

 private void SystemButtonClick(object sender, RoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(EventPage));
    }

I've modeled this after the Peer-to-peer navigation tutorial from microsoft, and can't find any significant differences. 我已经根据Microsoft 的对等导航教程对此进行了建模,并且找不到任何明显的不同。 The only similar issue I could find here was this , but that seemed to be due to the Template10 package which I'm not using. 我在这里可以找到的唯一类似问题是this ,但这似乎是由于我没有使用Template10软件包。

When the crash does occur, it goes to the App.gics file and complains that the debugger isn't configured to debug this unhandled exception. 当崩溃确实发生时,它将转到App.gics文件,并抱怨调试器未配置为调试此未处理的异常。

Does anyone have any idea why this might be happening? 有谁知道为什么会这样?

EDIT: To add, if I click the button to move to the current page, it reloads fine. 编辑:要添加,如果我单击按钮将移动到当前页面,它将重新加载正常。 I also just tried starting the program to the EventPage, which also prompted a crash. 我也只是尝试将程序启动到EventPage,这也提示了崩溃。

EDIT2: After some further testing, it seems I've located the source of the crash, though I don't understand it. EDIT2:经过一些进一步的测试后,尽管我不了解它,但似乎已经找到了崩溃的源头。

At the beginning of my EventPage class, I have a few variables: 在EventPage类的开头,我有一些变量:

public sealed partial class EventPage : Page
{
    private ObservableCollection<EventBin> EventCollection;
    private ObservableCollection<String> Systems;
    public EventPage()
    {
        this.InitializeComponent();
        Systems = SystemClass.GetSystems();
    }

It seems that the crass occurs when I assign the Systems variable. 当我分配Systems变量时,似乎出现了麻烦。 This doesn't occur with my identical operation for the other page, with a different variable. 我对其他页面执行相同的操作,但使用不同的变量时,不会发生这种情况。 The only difference being that in the MainPage, it's an ObservableCollection of a custom class rather than of strings. 唯一的区别是在MainPage中,它是自定义类而不是字符串的ObservableCollection。

If I re-initialize the System variable like this: 如果我像这样重新初始化System变量:

var Systems = SystemClass.GetSystems();

It runs, but doesn't connect to my bindings in the XAML. 它可以运行,但是没有连接到XAML中的绑定。

So, it turned out that the issue was that I had bound a custom type to the list in my data template, and then tried feeding it plain strings. 因此,事实证明,问题在于我已将自定义类型绑定到数据模板中的列表,然后尝试将其输入纯字符串。

<DataTemplate x:Key="System_DefaultItemTemplate"
                  x:DataType="local:SystemClass">
        <StackPanel>
            <TextBlock Text="{x:Bind Name}"/>
            <TextBlock Text="{x:Bind Site}"/>
        </StackPanel>
    </DataTemplate>

Since the strings obviously didn't have any Name or Site properties, it crashed. 由于这些字符串显然没有任何Name或Site属性,因此崩溃了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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