0

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 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.