1

私は問題があります。私は私のにバインドListViewしましたObservableCollection<ImageSource>

<ListView x:Name="FramesListView" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Disabled"
      ItemsSource="{Binding Path=FrameImages}" SelectionChanged="FramesListView_OnSelectionChanged">
<ListView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel
            Width="Auto"
            ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
            ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
    </ItemsPanelTemplate>
</ListView.ItemsPanel>

<ListView.ItemTemplate>
    <DataTemplate>
        <Border Width="100" Height="75" BorderThickness="1" BorderBrush="DarkGray" VerticalAlignment="Center" Margin="7,5,7,5">
            <StackPanel Orientation="Vertical">
                <Image Margin="5,5,5,5" Width="100" Height="75" Source="{Binding}" Stretch="Fill"></Image>
                <Label HorizontalAlignment="Center" Content="{Binding}"></Label>
            </StackPanel>
        </Border>
    </DataTemplate>
</ListView.ItemTemplate>
</ListView>

1つのことを除いて、すべてが正常に機能します。また、各画像の下にインデックスを表示したかったのです。私はこれを実現する方法がわかりません。

それを可能にするためにその行を変更する方法は?

<Label HorizontalAlignment="Center" Content="{Binding}"></Label>
4

1 に答える 1

2

私がかつて同様の状況で使用したややハックな解決策は、この目的のために AlternationIndex プロパティを使用することでした。AlternationCount を十分に高い数値に設定することにより、AlternationIndex プロパティはカウンターとして機能できます。

<ItemsControl x:Name="itemsControl" AlternationCount="100000">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Label Content="{Binding Path='(ItemsControl.AlternationIndex)', RelativeSource={RelativeSource AncestorType=ContentPresenter}}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

ただし、これには番号付けが 0 から始まるという欠点があります。

別のよりクリーンなソリューションには、ここで説明するように ValueConverter を作成することが含まれます: How can I bind against the Index of a ListBoxItem

于 2013-01-20T01:07:19.190 に答える