开发者

ListBox not updating in Windows Phone 7

开发者 https://www.devze.com 2023-01-23 09:43 出处:网络
I have a weird error which I can\'t figure out. I am creating a Windows Phone 7 app where I create PivotItems on the fly that contains a ListBox.

I have a weird error which I can't figure out.

I am creating a Windows Phone 7 app where I create PivotItems on the fly that contains a ListBox.

Heres the code -

        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 };

Now when I ever I add objects to PivotItems, nothing ever shows up in the UI.

Sorry for not being clear the first time - Here is the DataTemplate binding -

   <DataTemplate x:Key="PivotItemTempla开发者_如何学Cte">
        <StackPanel >
            <Image Source="{Binding URL}" ></Image>
            <TextBlock Text="{Binding Text}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
        </StackPanel>
    </DataTemplate>

I am adding the PivotItems to another OC which is binding to a Pivot control. All listings show up fine when I flick across PivotItems. Basically what I am guessing is that the OC is not triggering a refresh on the ListBox. Could I potential use BindingExpressions to force Refresh the list?


Your code doesn't show adding the newly create PivotItem to the Pivot. Is this what you're not doing.

This does of course assume that CorePivotItem is not already defined elsewhere.
Can you show your XAML and other C# code so we get the full picture.

0

精彩评论

暂无评论...
验证码 换一张
取 消