ItemsControl占用了Grid Row中的所有空间 [英] ItemsControl is taking up all the space within Grid Row
本文介绍了ItemsControl占用了Grid Row中的所有空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含3行的网格,我在其中分配了一个在文本块上进行渲染的ItemsControl。
I have a Grid with 3 Rows and I am assigning an ItemsControl within it that does Rendering on a textblock.
问题在于它运行时几乎占据整个屏幕。
The problem is when it runs it takes up almost the entire screen.
如何将ItemsControl限制为仅采用某个高度或仅使用Grid.Row高度可用的高度?
How can I limit the ItemsControl to only take a certain Height or use only what is available to it from the Grid.Row height?
<ItemsControl ItemsSource="{Binding RecordCollection, Mode=OneWay}" Grid.Row="1" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" ></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10,10,10,10" VerticalAlignment="Bottom">
<Border Name="br" Margin="3,10,3,10" CornerRadius="1"
Background="{Binding Color}"
Width="20" BorderBrush="{Binding Color}"
BorderThickness="1"
Height="{Binding Data}">
<!--<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0"
Storyboard.TargetName="br"
Storyboard.TargetProperty="(FrameworkElement.Height)"
Duration="0:0:02.0">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>-->
</Border>
<Border Padding="5">
<TextBlock FontWeight="Bold"
FontFamily="Latha" Text="{Binding Data}" >
<TextBlock.RenderTransform>
<TranslateTransform Y="-30"/>
</TextBlock.RenderTransform>
</TextBlock>
</Border>
<TextBlock Foreground="{Binding Color}"
FontWeight="Bold" FontFamily="Latha"
Text="{Binding Name}">
<TextBlock.RenderTransform>
<TranslateTransform Y="-20"/>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
推荐答案
我们帮助您显示网格的XAML。 而对于一个测试,取出动画,因为它很可能是真正的罪魁祸首。
For us to help you need to show the XAML for the grid. And for a test take out the animation as it is most likely the real culprit.
这篇关于ItemsControl占用了Grid Row中的所有空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文