[英]How do I stop Scrollviewer from expanding to infinite height?
我有一個網格,有3行。 第2行的高度可變,窗口可調整大小,而第3行的數據網格位於tabcontrol的scrollviewer中。
當滾動查看器中有很多項目時,滾動查看器會擴展直到達到可用的“最大高度”,但是最大高度是無限的,因此它會不斷增長。 我想要它做的就是停止擴展,如果這意味着它將父網格超出范圍,而是使用其滾動功能...這是它的常規布局:
<TabControl Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3">
<TabItem Header="Weapons">
<ScrollViewer>
<DataGrid>
...
</DataGrid>
</ScrollViewer>
</TabItem>
</TabControl>
那被保存在一個有3行3列的網格中。 第0行和第1行中有內容,我沒有放在這里,顯然我從Datagrid等中取出了不必要的信息。
我看到的例子:
根據要求,整個XAML。 並不是很短,這就是為什么我認為上面的簡化版本會更好。 XAML-太大而無法張貼
好,就在那里 我正在查看網格第2行上tabcontrol的不同選項卡中保存的兩個數據網格。
濃縮的“完整” xaml:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="1">
<Image Source="{StaticResource EmptySlot}" Margin="0" Width="34"/>
<Image Source="{Binding AuraSlot, FallbackValue={StaticResource AuraSlot}}" Margin="0" Width="34"/>
</Grid>
<Popup AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=MainWindowName}" IsOpen="{Binding WeaponTooltipOpen}" HorizontalOffset="{Binding WeaponOffsetX}" VerticalOffset="{Binding WeaponOffsetY}" PopupAnimation="Fade" OpacityMask="White" >
...
</Popup>
<Grid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3">
<Expander orizontalAlignment="Center">
<Expander.Header>
<TextBlock Text="Equipment Slots" HorizontalAlignment="Center" />
</Expander.Header>
<Grid Grid.Row="0" Grid.Column="1">
...
</Grid>
</Expander>
</Grid>
<TabControl Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3">
<TabItem Header="Weapons">
<Grid>
<ScrollViewer CanContentScroll="True" >
<DataGrid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding GroupedWeapons}" AutoGenerateColumns="False" IsReadOnly="True" AlternatingRowBackground="Gainsboro" AlternationCount="2" RowHeaderWidth="0">
<DataGrid.GroupStyle>
<GroupStyle>
...
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
...
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel>
...
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</ScrollViewer>
</Grid>
</TabItem>
</TabControl>
</Grid>
好的,最終發現了問題。
我真的不知道為什么這是問題的原因,因為這對我來說真的沒有意義,但是在代碼中,我將事情包裝在堆棧面板中。 堆放的僅有的兩件東西是一個文本塊和一個網格,該網格包含大量其他內容,包括與問題一起發布的所有代碼。 取出該堆棧面板使其能夠正常工作,因此,我現在使用2個differnetnet行將堆棧面板永久替換為另一個網格。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.