简体   繁体   English

XAML绑定在Windows Phone 8.1中不起作用

[英]XAML binding does not work in Windows Phone 8.1

I have a simple XAML page: 我有一个简单的XAML页面:

<Grid>
    <Grid Margin="50">
        <TextBlock Text="{Binding NowPlaying.tracktitle}" Foreground="White" FontSize="40"/>
        <TextBlock Foreground="#dcdcdc" FontSize="20" Margin="0,50,0,0">
            <Run Text="{Binding NowPlaying.artist}"/>
            <Run Text=" - "/>
            <Run Text="{Binding NowPlaying.album}"/>
        </TextBlock>
    </Grid>
</Grid>

With the Page code looking like this: 页面代码如下所示:

public sealed partial class test : Page
{
    // artistdata
    public now_playing NowPlaying { get { return App.nowplaying; } }

    public test()
    {
        this.InitializeComponent();
        this.DataContext = this;
    }
}

Whenever a property in App.nowplaying is changed the class fires a notifychanged event. 每当App.nowplaying中的属性被更改时,类就会触发notifychanged事件。 When the XAML receives this my app crashes with error: 当XAML收到此消息时,我的应用程序崩溃并出现错误:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in SYSTEM.NI.DLL

Anyone know how I could solve this? 有谁知道我怎么解决这个问题?

Also, the NotifyChanged event may have to be raised in the UI thread. 此外,可能必须在UI线程中引发NotifyChanged事件。

Something like this: 像这样的东西:

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
    PropertyChanged(this, new sc.PropertyChangedEventArgs(propertyName));
});

A first chance exception, is trigger by Visual Studio not the application. 第一次机会异常是Visual Studio而不是应用程序触发的。 Look closely at the error. 仔细看看错误。 Type e,in to Watch list or look into Locals list. 键入e,进入监视列表或查看“本地”列表。 And I would advise you to read about mvvm pattern. 我建议你阅读有关mvvm模式的内容。

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

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