WPF:「ショーはもっと」どこのクリックでコレクションをバインディングに既にあるitemControlで残りの項目を読み込むと同じようにボタンを追加します

プラハ:

こんにちは私は、UI要素のリストでitemControlを持つWPF(XAML)に少し新しいです。バインディングは、コレクションのプロパティで行われているところ。今、私の要件は、リストからのみ第一の要素を表示するために最初にされ、コレクションからのアイテムの残りを表示することのリストをクリックの終わり時に+ショーMoreボタンオプションを持ちます。..

<ItemsControl x:Name="ContentRoot" ItemsSource="{Binding MyCollections}">
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <grid>
        <TextBox Text="{Binding }" /> 
        <TextBox Text="{Binding }" />    
        </grid>
    </DataTemplate>
</ItemsControl.ItemTemplate>

Corentinペイン:

あなたは、両方のA持つことができますContentControl(コレクションの最初の項目を表示する)とItemsControlする場合にのみ(コレクション全体を表示)表示ToggleButton例えばチェックされます。

<StackPanel>
    <StackPanel.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <DataTemplate DataType="{x:Type local:MyViewModel}">
            <Grid>
                <TextBox Text="{Binding}" />
            </Grid>
        </DataTemplate>
    </StackPanel.Resources>
    <ContentControl Content="{Binding MyCollection[0]}"/>
    <ToggleButton x:Name="toggle" Content="Show more"/>
    <ItemsControl ItemsSource="{Binding MyCollection}" Visibility="{Binding ElementName=toggle, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</StackPanel>

次に、あなたの正確なニーズに合わせて、これを適応させることができます。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=369731&siteId=1