【问题标题】:ListBox not updating in Windows Phone 7列表框未在 Windows Phone 7 中更新
【发布时间】: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 来强制刷新列表吗?

【问题讨论】:

标签: data-binding windows-phone-7


【解决方案1】:

您的代码未显示将新创建的PivotItem 添加到Pivot。这是你没有做的吗?

这当然假设 CorePivotItem 尚未在其他地方定义。
您能否展示您的 XAML 和其他 C# 代码,以便我们了解全貌。

【讨论】:

  • 使问题更加清晰。谢谢大家的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 2011-10-17
  • 2011-05-23
  • 1970-01-01
  • 2014-09-21
  • 2012-12-24
  • 2011-10-29
相关资源
最近更新 更多