xaml – ListBoxItem Horizo??ntalContentAlignment在ListBox的
发布时间:2020-12-14 01:46:12 所属栏目:Windows 来源:网络整理
导读:我在 Windows Phone 8应用程序上的ListBoxItem有一个问题,同时试图让它们在ListBox的所有宽度上伸展. 我的列表框 ListBox ItemsSource="{Binding Events}" behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}" ItemTemplate="{Sta
|
我在
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的内容来尝试节省空间;给它可怕的透明胶带看. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-phone-8 – 获取应用程序版本Windows Phone 8
- Windows 2008上每个NIC有多个Vlan
- windows-server-2008 – Windows Server 2008 R2 – 如何更
- windows-server-2008 – 如何追踪Windows Server 2008崩溃的
- rdc – 无法远程桌面进入非域加入的工作组Windows Hyper-V
- 如何获取Win32中的内核数量?
- windows-7 – Windows 7上的多个鼠标光标
- windows-server-2008-r2 – 如何使用命令行获取IIS 7.5中绑
- Windows认证为基于Java的Web应用程序,如何?
- windows – 批处理脚本使其他批处理文件访问setlocal变量
