【发布时间】:2015-10-14 11:56:15
【问题描述】:
我正在尝试做一些简单的数据绑定。我有一个集合,它返回一个具有名为 MenuName 的属性的项目。我已经检查它是否正确返回。所以这就是我尝试进行绑定的方式。 (由 Menu 继承自 INotifyPropertyChanged。)
XAML
<Grid x:Name="LayoutRoot" DataContext="MenuItems">
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Grid.Row="0" Margin="24,17,0,28">
<TextBlock Text="Test" Typography.Capitals="SmallCaps"/>
<TextBlock Text="{Binding MenuName }" Margin="0,12,0,0" FontSize="52"/>
<CheckBox>Cache</CheckBox>
</StackPanel>
</Grid>
代码背后:
#region Members
MyAppWinConnectionClient MyAppWinService;
#endregion Members
#region Properties
public ObservableCollection<Menu> MenuItems { get; set; }
#endregion Properties
public StandardUI()
{
MyAppWinService = new MyAppWinConnectionClient();
this.InitializeComponent();
LoadTest();
}
private async void LoadTest()
{
try
{
MenuItems = await MyAppWinService.GetMenuEntriesAsync();
}
catch (FileNotFoundException ex)
{
}
}
我想我遗漏了一些明显的东西。你怎么看?
【问题讨论】:
-
好的,我通过将 INotifyPropertyChanged 添加到我的类并添加相应的 PropertyChanged 事件来解决它。
标签: c# wpf wcf silverlight windows-phone-8.1