Philippe Maes
Philippe Maes

Reputation: 510

XAML binding does not work in Windows Phone 8.1

I have a simple XAML page:

<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. When the XAML receives this my app crashes with error:

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

Anyone know how I could solve this?

Upvotes: 0

Views: 733

Answers (2)

Alita
Alita

Reputation: 36

Also, the NotifyChanged event may have to be raised in the UI thread.

Something like this:

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

Upvotes: 2

IceFog
IceFog

Reputation: 310

A first chance exception, is trigger by Visual Studio not the application. Look closely at the error. Type e,in to Watch list or look into Locals list. And I would advise you to read about mvvm pattern.

Upvotes: 0

Related Questions