Silverlight 网格:左侧应拉伸,右侧已定义
我正在尝试为列表项模板制作网格。应该有三列,第二列和第三列应该各有 50px 宽,第一列应该拉伸以填充其余的空白空间。
到目前为止,这是我的代码:
<DataTemplate x:key="NoteItemTemplate">
<Grid Background="{Binding ColorBrush}"
Height="50"
Margin="5,5,5,5"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
</Grid>
</DataTemplate>
<!-- far away, in an another file.. -->
<ListBox
x:Name="NotesListBox"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Top"
ItemsSource="{Binding NotesList}"
ItemTemplate="{StaticResource NoteItemTemplate}"
Background="AliceBlue" />
1* 或 * 没有区别。
但我似乎找不到答案。你会怎么做?
I'm trying to make a grid for a listitem template. There should be three columns, the second and third columns should be 50px wide each, the first column should stretch too fill the rest of the empty space.
Here's my code so far:
<DataTemplate x:key="NoteItemTemplate">
<Grid Background="{Binding ColorBrush}"
Height="50"
Margin="5,5,5,5"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
</Grid>
</DataTemplate>
<!-- far away, in an another file.. -->
<ListBox
x:Name="NotesListBox"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Top"
ItemsSource="{Binding NotesList}"
ItemTemplate="{StaticResource NoteItemTemplate}"
Background="AliceBlue" />
Makes no difference if it's 1* or *.
But I can't seem to find the answer. How would you do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提到您想要使用上面的 Grid 定义作为 ListBoxItem 的 DataTemplate。默认情况下,ListBoxItem 的内容不会拉伸,因此在您的情况下您只会看到 2 列。
所以我认为您需要指定您想要拉伸 ListBoxItem 的内容。这样做:
You mentioned that you want to use the above Grid definition as DataTemplate for an ListBoxItem. By default, the content of an ListBoxItem is not stretched, so that in your case you will only see 2 columns.
So I think you need to specify, that you want to stretch the content of the ListBoxItem. Do it like so: