如何在ListBox控件的所有角落设置项目。 [英] How sets items in all corners of ListBox control.

查看:58
本文介绍了如何在ListBox控件的所有角落设置项目。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我在WPF中很绿,但我找不到这个谜题的答案:



i在DataTemplate中有一些数据:

Maybe i'm green in WPF but i didn't find an answer for this puzzle:

i have some data in DataTemplate:

<DataTemplate x:Key="ItemTemplate">
<Grid Background="#FFE42121">
<Grid.RowDefinitions>
<RowDefinition Height="0.33*"/>
<RowDefinition Height="0.15*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.85*"/>
<ColumnDefinition Width="0.15*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="upperText" Text="{Binding LowerLabel}" VerticalAlignment="Stretch" Grid.ColumnSpan="1" />
<TextBlock x:Name="lowerText" Text="{Binding UpperLabel}" Grid.ColumnSpan="1" Grid.Row="1" Grid.Column="0"Grid.RowSpan="2"/>
<TextBlock x:Name="testValue" Text="{Binding TestsNumber}"Grid.ColumnSpan="1" Grid.Row="0" Grid.Column="1" />
<TextBlock x:Name="shotsValue" Text="{Binding ShotsNaumber}" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="1" Grid.Column="1"/>
</Grid>
</DataTemplate>

和ListBox控件:

, and the ListBox control:

<ListBox Margin="0" ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}"/>

尽管我的努力,数据[来自dataTemplate]从未填写过ListBox的字段。它始终与左对齐。
$


如何使用像我这样的数据设置ListBox控件的所有角落中的项目?

Despite my efforts the data[from dataTemplate] never FILLed the field of ListBox. It is always alignment to left.

How sets items in all corners of ListBox control with data like mine?

 

 

推荐答案

列表框将所有项目放入StackPanel,然后每个项目给出listboxitem只需要它所需的空间。在您的情况下,什么不能按预期工作? 你想尝试对齐某些东西吗?
A listbox puts all of its items into a StackPanel, which in turn gives each listboxitem only the space it needs. What isn't working as you expect in your case?  Are you trying to right align something?


这篇关于如何在ListBox控件的所有角落设置项目。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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