2010-11-05 108 views
1

我有一個奇怪的錯誤,我不明白。列表框不在Windows Phone 7更新

我正在創建一個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到另一個OC被綁定到一個樞軸控件。當我滑過PivotItems時,所有列表都顯示正常。基本上我猜測的是OC不會觸發ListBox上的刷新。我可以使用BindingExpressions強制刷新列表嗎?

+1

是你的項目模板絕對好嗎?如果你沒有指定它(使用默認的),你會得到*東西*顯示出來嗎? – 2010-11-05 07:14:52

+0

這是相同的問題,在http://stackoverflow.com/questions/4114608/databound-pivot-control-is-not-creating-the-first-pivotitem – 2010-11-08 12:44:15

回答

0

您的代碼未顯示將新創建的PivotItem添加到Pivot。這是你沒有做的事情嗎?

這當然假定CorePivotItem尚未在其他地方定義。
你可以顯示你的XAML和其他C#代碼,這樣我們就可以看到完整的圖片。

+0

增加更清晰的問題。謝謝你們的幫助! – ankitb 2010-11-05 17:12:24