Question

I'm trying to create a scrollable area to display controls using the XAML code below. My problem is that I only see one item displayed when the items are rendered. I'm using an ObservableCollection for the data.

I've attached to the CollectionChanged event on the collection and definitely see multiple items being added but the view always displays only one item.

If I manually place HubTiles inside the WrapPanel (not databound) the tiles show up correctly. Also I tried replacing the hub tile with a button control and I do see multiple buttons, so I'm wondering if perhaps there is some issue with the HubTile control.

Here's my XAML:

<Grid x:Name="dataGrid" Grid.Row="1">
        <ScrollViewer x:Name="myPanel" HorizontalAlignment="Stretch" Width="Auto" Margin="0" >
            <toolkit:WrapPanel MaxWidth="{Binding ActualWidth, ElementName=myPanel, Mode=OneWay}" Margin="0" HorizontalAlignment="Center" ItemHeight="230" ItemWidth="230">
                <ItemsControl x:Name="images">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <toolkit:HubTile 
                                Style="{Binding Source={StaticResource media}}"
                                Message="{Binding Data.Caption}"
                                Source="{Binding Data.Source}"
                                />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </toolkit:WrapPanel>
        </ScrollViewer>
    </Grid>
Était-ce utile?

La solution

Difficult to say without more information, but the first thing I noticed is that you have a WrapPanel in a ScrollViewer, and that WrapPanel contains an ItemsControl, with a WrapPanel as ItemsPanel.

The "inner" WrapPanel doesn't have an ItemWidth or ItemHeight. Is there any reason you have two WrapPanel's?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top