xaml – ListBoxItem Horizo​​ntalContentAlignment在ListBox的整个宽度上拉伸

我在 Windows Phone 8应用程序上的ListBoxItem有一个问题,同时试图让它们在ListBox的所有宽度上伸展.

我的列表框

<ListBox 
      ItemsSource="{Binding Events}" 
      behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}"
      ItemTemplate="{StaticResource EventListTemplateSelector}"/>

它的DataTemplates是一个单独的xaml资源文件

<DataTemplate x:Key="EventListHeaderTemplate">
    <Border HorizontalAlignment="Stretch">
        <Grid Height="50">
            <Grid.ColumnDeFinitions>
                <ColumnDeFinition Width="*"/>
                <ColumnDeFinition Width="6*"/>
            </Grid.ColumnDeFinitions>
            <Image Grid.Column="0" Source="{Binding ImageUri}" VerticalAlignment="Center" HorizontalAlignment="Center" Height="30"/>
            <TextBlock Grid.Column="1" Text="{Binding SomeText}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="Black"/>
        </Grid>
    </Border>
</DataTemplate>

我不能得到真正弹力的物品,我不知道问题在哪里.我试图设置ItemContainerStyle Horizo​​ntalCOntentAlignment =“Stretch”,它没有工作.我尝试了许多其他组合,似乎只有将边框或网格宽度设置为常量工作,而另一种解决方案的作用是将边框宽度设置为绑定到包含ListBox的ActualWidth,但是我想使用Stretch变种如果可以使它工作.

我在开发商业WP8应用程序时遇到同样的问题,并且让我坚持想知道为什么我的TextBlock在整个宽度上没有完全着色.

使用竞争样式(这适用于任何xaml变体实际上)的方式是明确定义ListBoxItem的样式来处理空间使用.

这给了xaml一个提示,它以这种方式填充(拉伸)到屏幕区域:

<ListBox Name="lbTest" HorizontalContentAlignment="Stretch"  >

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

        <ListBox.ItemTemplate>...</ListBox.ItemTemplate>

否则,xaml解析器认情况下通过将其自动调整为ListBoxItem的内容来尝试节省空间;给它可怕的透明胶带看.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...