0

I have this XAML:

            <WrapPanel Orientation="Horizontal" Margin="10" HorizontalAlignment="Center">
            <ItemsControl ItemsSource="{Binding Raccourcis}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Content="{Binding Contenu}" Width="25" Height="25" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </WrapPanel>

On the context side, I have that:

    public ObservableCollection<Raccourci> Raccourcis
    {
        get
        {
            return m_raccourcis;
        }

        set
        {
            m_raccourcis = value;
            OnPropertyChanged("Raccourcis");
        }
    }

public class Raccourci
{
    public string Contenu { get; set; }
}

I just want to have buttons displayed horizontally but I get:

screenshot

I'd like to have them with an horizontal alignement. Unfortunatly this answer ItemsControl with horizontal orientation does not seem relevant in my case...

Community
  • 1
  • 1
Benoît
  • 87
  • 8

1 Answers1

0

This XAML fixes the problem:

<ItemsControl ItemsSource="{Binding Raccourcis}">

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

    <ItemsControl.ItemTemplate>
         <DataTemplate>
              <Button Content="{Binding Contenu}" Width="25" Height="25" />
         </DataTemplate>
    </ItemsControl.ItemTemplate>

</ItemsControl>

result

Clemens
  • 123,504
  • 12
  • 155
  • 268
Benoît
  • 87
  • 8