2014-05-08 47 views
0

我有一個簡單的XAML頁面:XAML綁定Windows Phone中不起作用8.1

<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> 

與頁面的代碼看起來像這樣:

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

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

每當App.nowplaying一個屬性更改該類將觸發notifychanged事件。當XAML收到我的應用程序崩潰的錯誤:

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

任何人都知道我可以解決這個問題嗎?

回答

2

此外,可能必須在UI線程中引發NotifyChanged事件。

事情是這樣的:

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

沒錯這就是我發現了什麼來解決這個問題,以及 –

0

第一次機會異常,由Visual Studio觸發而不是應用程序。仔細看看錯誤。輸入e,進入觀察列表或查看當地人列表。 我建議你閱讀有關mvvm模式。