我在XAML中有以下场景:
<Grid Grid.IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid x:Name="gridLabels" Grid.Column="0">
<Grid.RowDefinitions>
<Row SharedSizeGroup="FirstRow" MinHeight=24/>
<Row SharedSizeGroup="SecondRow" MinHeight=24/>
<Row SharedSizeGroup="ThirdRow" MinHeight24/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0">Top Item:</TextBlock>
<TextBlock Grid.Row="1">Middle Item:</TextBlock>
<TextBlock Grid.Row="2">Bottom Item:</TextBlock>
</Grid>
<ScrollViewer x:Name="scrVwItems" Grid.Column="1" VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Visible" >
<ItemsControl ItemSource="{Binding Bondage}">
<!--etc-->
</ItemsControl>
</ScrollViewer>
</Grid>
在ItemsControl中,DataTemplate
d个项目都有自己的网格,并设置了SharedSizeGroup,以便TextBlock
s等与最左边的TextBlock标签对齐。
我得到的问题是,在填充ItemsControl之前,SharedSizeGroup
不会排队,而“Bottom Item:”文本会与我的ScrollViewer的水平滚动条一起下降。
有没有一种简单的方法可以将“gridLabels”网格与ScrollViewer的内容区域对齐,而不是整个ScrollViewer本身?
答案 0 :(得分:1)
排序,只是给ItemsControl(ScrollViewer的内容)一个名称,并使用ElementName绑定到它的“gridLabels”中的ActualHeight .Height。还将MinHeight应用于ItemsControl。
<Grid Grid.IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid x:Name="gridLabels" Grid.Column="0"
Height={Binding ElementName=myItemsControl, Path=ActualHeight}">
<Grid.RowDefinitions>
<Row SharedSizeGroup="FirstRow" MinHeight=24/>
<Row SharedSizeGroup="SecondRow" MinHeight=24/>
<Row SharedSizeGroup="ThirdRow" MinHeight24/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0">Top Item:</TextBlock>
<TextBlock Grid.Row="1">Middle Item:</TextBlock>
<TextBlock Grid.Row="2">Bottom Item:</TextBlock>
</Grid>
<ScrollViewer x:Name="scrVwItems" Grid.Column="1" VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Visible" >
<ItemsControl ItemSource="{Binding Bondage}" x:Name="myItemsControl" MinHeight="150">
<!--etc-->
</ItemsControl>
</ScrollViewer>
</Grid>