我已经能够轻松地在页面之间传输对象,但现在我无法在 xaml 标记中显示数据。
这是存储在应用程序的 sdf 文件中的 Quote 实体:
[Table]
public class Quote
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id { get; set; }
[Column(CanBeNull = false)]
public string QuoteOfTheDay { get; set; }
[Column(CanBeNull = false)]
public string SaidBy { get; set; }
[Column(CanBeNull = true)]
public string Context { get; set; }
[Column(CanBeNull = true)]
public string Episode { get; set; }
[Column(CanBeNull = true)]
public string Season { get; set; }
}
这是后面的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
DataContext = this;
var quote = PhoneApplicationService.Current.State["q"];
Quote quoteToDisplay = (Quote)quote;
}
public static readonly DependencyProperty QuoteToDisplayProperty = DependencyProperty.Register(
"QuoteToDisplay", typeof(Quote), typeof(PhoneApplicationPage), new PropertyMetadata(default(Quote)));
public Quote QuouteToDisplay
{
get { return (Quote)GetValue(QuoteToDisplayProperty); }
set { SetValue(QuoteToDisplayProperty, value); }
}
xml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock FontSize="36" FontFamily="Verdana" FontWeight="ExtraBlack" Text="{Binding QuoteToDisplay.QuoteOfTheDay}" />
</Grid>
我得到了要在 xaml 中显示的确切数据。我想在 TextBlock 中显示 QuoteOfTheDay 属性。但是每次我尝试使用 {Binding} 时,TextBlock 总是为空的。当我也尝试使用绑定时,智能感知不建议“QuoteOfTheDay”。
我显然错过了一些重要的事情,但我真的看不出它是什么。