wpf边框控件可跨越listboxItem的宽度 [英] wpf border control to span the width of listboxItem

查看:109
本文介绍了wpf边框控件可跨越listboxItem的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的wpf应用程序中的业务对象定义一个dataTemplate,该对象的集合已绑定到ListBox.

Im trying to define a dataTemplate for a business object in my wpf application a collection of which is being bound to a ListBox.

<UserControl.Resources>
    <DataTemplate x:Key="ResizedItemsDataTemplate" DataType="{x:Type resizer:ResizeMonitorItem}">
              <Border x:Name="bdr" BorderBrush="Blue" 
                                     BorderThickness="1" 
                                     CornerRadius="2" 
                                     Width="auto"
                                     HorizontalAlignment="Stretch"
                                     VerticalAlignment="Stretch">
                    <Grid Margin="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="14"></RowDefinition>
                            <RowDefinition Height="14"></RowDefinition>
                        </Grid.RowDefinitions>


                        <TextBlock Grid.Row="0" Text="{Binding SaveAsFileName}"></TextBlock>
                        <TextBlock Grid.Row="1" Text="{Binding ResizedImageFilePath}"></TextBlock>
                    </Grid>
             </Border>
    </DataTemplate>
</UserControl.Resources>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0">    
    <Border BorderThickness="0,0,0,5" BorderBrush="DarkGray" >
        <ListBox x:Name="ListBoxResizeItems" ItemsSource="{Binding Path=ResizeItems}" BorderThickness="0" ItemTemplate="{DynamicResource ResizedItemsDataTemplate}">
        </ListBox>
    </Border>
</Grid>

如何获取x:Name = bdr定义的边框以跨越每个列表框项目的整个宽度?目前,它仅跨越其中的文本块的,这些文本块不必填充listboxitem的整个宽度,并且对于每个listboxitem也会有所不同.

How can I get the border defined with x:Name=bdr to span the full width of each listbox item? At the moment it only spans the with of the textblocks inside it which dont neccessary fill the full width of the listboxitem and also vary for each listboxitem.

推荐答案

这可能与ListBoxItems本身没有占用ListBox的整个宽度有关.将HorizontalContentAlignment="Stretch"属性添加到ListBox中,然后查看它是否可以拉伸单个项目以填充宽度.

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.

这篇关于wpf边框控件可跨越listboxItem的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆