[英]XAML binding does not work in Windows Phone 8.1
我有一個簡單的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>
頁面代碼如下所示:
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
有誰知道我怎么解決這個問題?
此外,可能必須在UI線程中引發NotifyChanged事件。
像這樣的東西:
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
PropertyChanged(this, new sc.PropertyChangedEventArgs(propertyName));
});
第一次機會異常是Visual Studio而不是應用程序觸發的。 仔細看看錯誤。 鍵入e,進入監視列表或查看“本地”列表。 我建議你閱讀有關mvvm模式的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.