wpf border control to span the width of listboxItem

烈酒焚心 提交于 2019-12-03 01:45:22
Matt Hamilton

This is probably more to do with the ListBoxItems themselves not taking up the full width of the ListBox. Add the HorizontalContentAlignment="Stretch" attribute to your ListBox and see if it stretches the individual items to fill the width.

Worked it out. The trick is to set the HorizontalContentAlignment="Stretch" on your listbox to make its contents stretch the full width rather than fit the contents only.

 <ListBox x:Name="ListBoxResizeItems" 
                HorizontalContentAlignment="Stretch"
                ItemsSource="{Binding Path=ResizeItems}" 
                BorderThickness="0"                                         
                ItemTemplate="{DynamicResource ResizedItemsDataTemplate}" >
        </ListBox>

Sorry Matt, just got your answer thorugh as I was typing this post.

Dale Barnard

HorizontalContentAlignment is a nice, clean solution compared to what I was trying. Thanks!

Here's what ALMOST worked, but sometimes made a dialog box animated itself wider and wider forever:

Width="{Binding ActualWidth, 
        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!