使用 Prism,我实现了与 StockTraderRI 项目非常相似的 View、Model 和 Presenter。我的问题是我正在尝试将堆栈面板数据绑定到 ObservableCollection 对象,但没有显示任何字符串。
这是我的代码:
演示模型代码:
public InfoBarPresentationModel(IInfoBarView view, IEventAggregator eventAggregator)
{
this.View = view;
this.View.Model = this;
InfoBarItems = new ObservableCollection<string>();
InfoBarItems.Add("Test 1");
InfoBarItems.Add("Test 2");
}
public IInfoBarView View { get; set; }
public ObservableCollection<string> InfoBarItems { get; set; }
XAML 代码:
<ItemsControl x:Name="list" ItemsSource="{Binding InfoBarItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我尝试了多种绑定组合,但还没有弄清楚为什么我的字符串从未出现过。我究竟做错了什么?
瑞克