views:

616

answers:

2

Hi, I am binding a list of items to a ListBox, I need some help with XAML to be able to display a button for each item. I can display a button fine, however the button takes on the length of the content text. I want my button to consume 100% of the ListBox width. I also need to stop the row highlighting for the ListBox, as the button should do this itself.

I am using a button rather than drawing rectangles as I want to use Commands for click event on the Button.

<ListBox x:Name="MenuListBox" 
         ItemsSource="{Binding Path=MenuItemList}" 
         ScrollViewer.VerticalScrollBarVisibility="Visible">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="1">
                <Button Content="{Binding Path=Name}" 
                        Height="30" 
                        FontSize="12" 
                        FontWeight="Bold"
                        HorizontalAlignment="Stretch"
                        Command="{Binding Path=DataContext.GetChildrenCommand, Source={StaticResource spy}}" 
                        CommandParameter="{Binding}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
A: 

Just worked it out, the ListBox definition requires:

**HorizontalContentAlignment="Stretch"**
A: 

Remove the VerticalAlignment and HorizontalAlignment properties from the Grid, and perhaps is ListBox not the Control you need.. Try the ItemsControl instead so you wont have the selection things of Listbox..

Arcturus