【发布时间】:2010-11-05 07:11:54
【问题描述】:
我有一个奇怪的错误,我无法弄清楚。
我正在创建一个 Windows Phone 7 应用程序,在其中动态创建包含 ListBox 的 PivotItems。
这是代码 -
PivotItems = new ObservableCollection<StatusItem>();
DataTemplate itemTemplate = App.Current.Resources["PivotItemTemplate"] as DataTemplate;
ListBox itemBox = new ListBox();
itemBox.ItemsSource = PivotItems;
itemBox.ItemTemplate = itemTemplate;
CorePivotItem = new PivotItem() { Header = header, Content = itemBox };
现在,当我向 PivotItems 添加对象时,UI 中没有任何显示。
抱歉第一次没看清楚-这里是DataTemplate绑定-
<DataTemplate x:Key="PivotItemTemplate">
<StackPanel >
<Image Source="{Binding URL}" ></Image>
<TextBlock Text="{Binding Text}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
我正在将 PivotItems 添加到另一个绑定到 Pivot 控件的 OC。当我浏览 PivotItems 时,所有列表都显示得很好。基本上我的猜测是 OC 没有触发 ListBox 的刷新。我可以使用 BindingExpressions 来强制刷新列表吗?
【问题讨论】:
-
你的物品模板确定没问题吗?如果你不指定它(使用默认的)你会得到 something 出现吗?
-
这与stackoverflow.com/questions/4114608/…中的问题是否相同
标签: data-binding windows-phone-7