Search code examples
wpfalignmentlistviewitem

Horizontal Alignment ListViewItem


I need to put my listviewitems Horizontally, but I can't find the way, so far I tried this:

 <ListView Grid.Row="0" ItemsSource="{Binding Path=Cells, UpdateSourceTrigger=PropertyChanged}" 
                        ItemTemplate="{StaticResource CellGroupTemplate}"
                        Background="{StaticResource EnvLayout}"
                        HorizontalContentAlignment="Stretch">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Style.Resources>
                                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
                                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                            </Style.Resources>
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>

my items are other UI controls, with their viewmodel attached

 <DataTemplate DataType="{x:Type vm:CellItemViewModel}" x:Key="CellGroupTemplate">
        <vw:CellItemView/>
    </DataTemplate>

Can someone tell me how to put each Element (datatemplate) next to the other

Thank you


Solution

  • You can set a custom items panel for your ListView:

     <ListView>
         <ListView.ItemsPanel>
             <ItemsPanelTemplate>
                 <StackPanel Orientation="Horizontal" />
             </ItemsPanelTemplate>
         </ListView.ItemsPanel>
     </ListView>