【发布时间】:2015-11-30 02:51:02
【问题描述】:
我想在 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>
这里的问题是,当我展开其中一个扩展器时。以及扩展的控件高度增加(我想要),同一行中的所有其他控件也增加了高度。
有没有办法阻止同一行中的所有其他控件增加高度?
提前感谢您的帮助。
【问题讨论】:
-
无法重现你的问题,尝试用图解释。
-
@AnjumSKhan 我重现,也许你需要在代码隐藏的“数据”中添加一些项目。第一个答案解决了它。
-
@LeiYang 我看不到我的控件在高度中增长。 share.pho.to/9u3cc
-
@LeiYang 对不起,我明白了。