views:

47

answers:

1

Currently i have a user control which contains a listbox of other visual element user controls; which (for this special case) have been data templated.

<Grid>
    <ListBox ItemSource="{Binding Path=UserControlCollection}">
        <ListBox.ItemTemplate>
             <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                      <ContentPresenter Content="{Binding}"/>
                      <Button/>
                  </StackPanel>
             </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

The issue is that i have This Issue. And because of the data template, i can't seem to find a way to correct the styling issue.

Any help would be greatly appreciated.

+1  A: 

I found by overriding the ListBoxItem's horizontalcontentalignment and verticalcontentalignment i was able to correct the issue.

 <ListBox.ItemContainerStyle>
     <Style TargetType="ListBoxItem">
         <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
         <Setter Property="VerticalContentAlignment" Value="Stretch"/>
     </Style>
 </ListBox.ItemContainerStyle>

I also found changing to a listview helpful but did have issues of its own.

Val