我想在ItemControl中查看UserControls hostest,使用WrapPanel作为ItemsPanelTemplate,例如,我有
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5">No to load</TextBlock>
<TextBox Name="NumBox" Width="80" Margin="5">1000</TextBox>
<Button Width="80" Height="25" Click="LoadClick">Load</Button>
<Button Click="ClearClick" Margin="5">Clear</Button>
</StackPanel>
<ScrollViewer Grid.Row="1" Margin="3" VerticalScrollBarVisibility="Auto" >
<ItemsControl ItemsSource="{Binding Data}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:TestControl2></local:TestControl2>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
TestControl2定义如下..
<UserControl x:Class="WpfWrapPanelTest.TestControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Height="Auto" Width="120" Margin="10">
<Border Background="Bisque" CornerRadius="10" Height="Auto">
<StackPanel>
<Expander Header="Options 1" ExpandDirection="Down">
<StackPanel>
<TextBlock>Item1</TextBlock>
<TextBlock>Item2</TextBlock>
</StackPanel>
</Expander>
<Expander Header="Options 2" ExpandDirection="Down">
<StackPanel>
<TextBlock>Item1</TextBlock>
<TextBlock>Item2</TextBlock>
<TextBlock>Item3</TextBlock>
<TextBlock>Item4</TextBlock>
</StackPanel>
</Expander>
</StackPanel>
</Border>
</UserControl>
这里的问题是当我展开其中一个扩展器时......控件扩展了高度增长(我想要),同一行中的所有其他控件也会增加高度。
有没有办法阻止同一行中的所有其他控件从高处增长?
提前感谢您的帮助。
答案 0 :(得分:3)
此处的问题是VerticalAlignment
的{{1}}属性默认为FrameworkElement
。您需要通过指定其他垂直对齐来在树中的某个点处中断此项。我的建议是将您的DataTemplate更改为:
Stretch