Ric*_*ich 12 wpf resize wrappanel itemscontrol binding-expressions
我有一个有几行的网格.在顶行,我有一个ItemsControl动态绑定到一个集合,并使用DataTemplateSelector和ItemsPanelTemplate(与一个水平排列的WrapPanel).这是我到目前为止的精简版:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="2" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridSplitter Background="#666" Grid.Row="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<ItemsControl x:Name="items" Background="#DDD" Grid.Row="0" ItemTemplateSelector="{StaticResource itemTemplateSelector}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我不想将第一行的高度设置为40,而是根据ItemsControl必须适合其所有内容的最小高度动态设置它.由于ItemsControl的高度受Grid Row高度的限制,我无法弄清楚我应该绑定哪个元素以及我应该将它绑定到哪个元素的属性.
将Grid Row的Height绑定到ItemsControl的"所需高度"是有意义的.所以,我找到了DesiredSize属性并将我的RowDefinition的高度绑定到ItemsControl的DesiredSize.Height.这在第一次加载时有效,但在我调整控件大小时不会更新(记住,我使用WrapPanel作为我的ItemsPanelTemplate,因此当我调整窗口大小时,ItemsControl的高度应该更改).
有没有人知道绑定框架是否支持这种情况,还是需要添加事件处理程序代码才能实现这一点?
谢谢.
Bub*_*rap 31
您是否尝试将高度设置为自动以达到您想要的效果:
<RowDefinition Height="Auto"/>
Run Code Online (Sandbox Code Playgroud)
(或者我在这里想的太简单了......?)
归档时间: |
|
查看次数: |
10809 次 |
最近记录: |