我一直坚持要在 WPF 中完成的项目,而我在 WPF 中的唯一经验是我在过去一周从互联网上获得的(主要是 SO)。因此,如果我的问题看起来很简单,或者即使对于一个笨蛋来说答案也很明显,那么我只能道歉并请求您的耐心!
这是构成我的主窗口的 XAML:
<Window>
<Grid Width="Auto" Height="Auto">
<StackPanel>
<DockPanel Margin="2">
<StackPanel Orientation="Horizontal">
<Border Name="leftPane" Height="Auto" CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="2" Padding="8">
<!-- Various controls here for the "left pane" -->
</Border>
<Separator BorderThickness="1" Margin="2"></Separator>
<Border Name="rightPane" Height="Auto" CornerRadius="6" BorderBrush="Gray" BorderThickness="2" Padding="0" Background="#FFF0F0F0">
<Canvas Name="canvasMain" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="Auto" Height="Auto">
<!-- I need to resize the rightPane and the canvasMain when the user manually resizes the main window -->
</Canvas>
</Border>
</StackPanel>
</DockPanel>
</StackPanel>
</Grid>
</Window>
窗口或多或少看起来像这样:
=================================================================
- -
- ------------- -------------------------------------------- -
- | Left Pane | | Right Pane | -
- | width:100 | | Need to expand width and height when | -
- | | | ...the main window is resized by the | -
- | | | ...user | -
- | | | | -
- | | | | -
- | | | | -
- | | | | -
- ------------- -------------------------------------------- -
=================================================================
我的第一个倾向是在主窗口的 SizeChanged 事件中简单地实现一些逻辑。但是在快速搜索了一下之后,我遇到了关于附加行为和属性触发器和事件触发器的主题,这反过来又让我想到,也许 SizeChanged 事件并不是最好的方法。
那么,简而言之,动态调整窗口内容大小的正确方法是什么?