我有填充控制的问题。
在第一列中,我有stackpanel,它有4个控件。 每个ScrollViewer作为DataContext都有TreeView,其高度设置为Auto。 当我在treviews中展开节点时,它会扩展到窗口外。我该如何解决?
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".30*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width=".69*"/>
</Grid.ColumnDefinitions>
<Border CornerRadius="0" BorderBrush="#58290A"
BorderThickness="5" Grid.Column="0" >
<StackPanel MaxHeight="{Binding Height, ElementName=MainGrid}">
<ScrollViewer x:Name="ScrollViewerForOperationTree">
</ScrollViewer>
<Button Content="Dodaj brakujący hotel" Click="AddHotel_Click" x:Name="btnAddHotel">
</Button>
<Button Content="Dodaj brakujące miasto" Click="AddCity_Click" x:Name="AddCity"></Button>
<ScrollViewer x:Name="ScrollViewerForSimpleTree"></ScrollViewer>
</StackPanel>
</Border>
<GridSplitter HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Grid.Column="1" ResizeBehavior="PreviousAndNext"
Width="5" Background="#FFBCBCBC"/>
<Grid Grid.Column="2" Background="#B5CBEF" x:Name="GridObjectOperation">
</Grid>
</Grid>
答案 0 :(得分:1)
StackPanel将为其子项提供尽可能多的垂直空间,即使没有足够的可用空间,因此后面的元素将会结束。请尝试使用网格:
<Border CornerRadius="0" BorderBrush="#58290A"
BorderThickness="5" Grid.Column="0" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" x:Name="ScrollViewerForOperationTree">
</ScrollViewer>
<Button Grid.Row="1" Content="Dodaj brakujący hotel"
Click="AddHotel_Click" x:Name="btnAddHotel">
</Button>
<Button Grid.Row="2" Content="Dodaj brakujące miasto"
Click="AddCity_Click" x:Name="AddCity"></Button>
<ScrollViewer Grid.Row="3" x:Name="ScrollViewerForSimpleTree">
</ScrollViewer>
</Grid>
</Border>