#424 – 使ListBox 中每一项保持一致大小(Getting Data-Bound Items in a ListBox to Be a Consistent Size)
来源:互联网 发布:人民大学数据库 编辑:程序博客网 时间:2024/06/02 07:30
之前演示了如何通过数据绑定向ListBox中添加丰富的内容。
但问题是在垂直方向上各项的内容并没有对齐。我们在数据模板中使用的是StackPanel,它会自动根据内容调整大小。
我们不希望它自动调整大小,而是所有的数据中相同的列有相同的宽度。
我们可以使用Grid.IsSharedSizeScope和SharedSizeGroup属性在所有子项中共享大小。
<ListBox ItemsSource="{Binding MovieList}" SnapsToDevicePixels="True" Grid.IsSharedSizeScope="True"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,0,0,5"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="Col1"/> </Grid.ColumnDefinitions> <Image Source="{Binding Image}" /> </Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="Col2"/> </Grid.ColumnDefinitions> <StackPanel Orientation="Vertical"> <Label Content="{Binding Title}" FontWeight="Bold"/> <Label Content="{Binding Year}"/> </StackPanel> </Grid> <Border BorderBrush="Black" BorderThickness="0.5"/> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="Col3"/> </Grid.ColumnDefinitions> <StackPanel Orientation="Vertical"> <Label Content="Actors:"/> <Label Content="{Binding ActorLead}" Margin="10,0"/> <Label Content="{Binding ActressLead}" Margin="10,0"/> </StackPanel> </Grid> <Border BorderBrush="Black" BorderThickness="0.5"/> <StackPanel Orientation="Vertical"> <Label Content="Director:"/> <Label Content="{Binding Director}" Margin="10,0"/> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate></ListBox>
原文地址:https://wpf.2000things.com/2011/11/07/424-getting-data-bound-items-in-a-listbox-to-be-a-consistent-size/
0 0
- #424 – 使ListBox 中每一项保持一致大小(Getting Data-Bound Items in a ListBox to Be a Consistent Size)
- #400 – 使用ItemsPanel 属性将WrapPanel 作为ListBox的显示面板(Using a WrapPanel as the Items Panel for a ListBox)
- MVVM :How to select multiple items in listbox
- 读Excel:Reading excel in a ListBox
- 以前的笔记或摘录:Get Listbox Items from a TWebBrowser Document?
- ListBox 显示最后一项
- How to hide the highlight of a listbox
- Incremental Searching for a ListBox
- How to bind listbox to data dynamically
- How To Sort Items in a CListCtrl in Report View
- #395 – 通过数据绑定丰富ListBox 的内容(Rich ListBox Content using Data Binding)
- C# listbox remove selected items
- 改变ListBox中Items的颜色,并且为ListBox中的项目添加图片。
- a pointer to a bound function may only be used to call the function
- a pointer to a bound function may only be used to call the function
- #748 – 获得按下时对应位置点的大小(Getting the Size of a Contact Point during Raw Touch)
- listbox
- listbox
- RecyclerView专家
- hdu 1698 Just a Hook
- sap hana backup issue
- ubuntu 14.04 挂载 nfs
- 大风歌
- #424 – 使ListBox 中每一项保持一致大小(Getting Data-Bound Items in a ListBox to Be a Consistent Size)
- java ArrayList与LinkedList的普通for循环遍历
- JSON 字符串 与 java 对象的转换
- 异常笔记
- c#--获取数据库指定表的所有列名
- 使用json-lib进行Java和JSON之间的转换
- linux配置静态IP后ping外网不通的解决方案-续
- hadoop启动脚本分析:start-all.sh
- SSH需要的全部jar详解