0

Silverlight 4 ListBox ItemsPanel の WrapPanel をドロップしても、何も表示されないのはなぜなのか、非常に当惑しています。ItemsPanel のみをコメント アウトすると、テキスト付きの小さな画像の通常の垂直リストが表示されます。WrapPanel が実際に存在することを確信させるために、WrapPanel に背景色を追加しました。骨の折れる何かが欠けていると思いますが、それは何ですか?

    <ListBox Grid.Row="1" Grid.Column="1"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             MinHeight="24"
             >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border> <StackPanel> <Image> <TextBlock> </StackPanel> </Border> (pseudo template)
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel Background="Orange" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
4

3 に答える 3

0

理由はわかりませんが、ItemsSourceをObservableCollectionに切り替えるとうまくいきました。デフォルトのItemsPanelの動作がdiffパネルと異なる理由はわかりませんが、実際に動作しました。

これを調べてくれてありがとう。

于 2011-05-29T21:29:25.437 に答える
0

Blend のサンプル データを使用してシナリオを再現しました。ラップ パネル内の項目を確認できます。

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
        x:Class="ASD_Answer012.MainPage"
        Width="640" Height="480">
        <UserControl.Resources>
            <DataTemplate x:Key="ItemTemplate">
                <StackPanel>
                    <TextBlock Text="{Binding Property1}"/>
                    <CheckBox IsChecked="{Binding Property2, Mode=TwoWay}"/>
                    <Image Source="{Binding Property3}" HorizontalAlignment="Left" Height="64" Width="64"/>
                </StackPanel>
            </DataTemplate>
            <ItemsPanelTemplate x:Key="ItemsWrapPanelTemplate">
                    <toolkit:WrapPanel Background="DarkOrange"/>
            </ItemsPanelTemplate>
        </UserControl.Resources>

        <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <ListBox Grid.Column="1" Grid.Row="1" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Collection}" ItemsPanel="{StaticResource ItemsWrapPanelTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
        </Grid>
    </UserControl>

これは私が得るものです: ラップパネルアイテム

より詳細な XAML を提供すると、正確な問題を再現して解決できる可能性があります。

于 2011-05-29T16:27:50.370 に答える
0

あなたのアイテムテンプレートには何も実体がありません - それは空の要素でいっぱいです. そこに何かを入れると、結果が表示されるはずです。例えば:

<DataTemplate>
    <TextBlock>Test</TextBlock>
</DataTemplate>
于 2011-05-28T15:57:17.583 に答える