【发布时间】:2013-07-16 14:55:08
【问题描述】:
在我的 WPF 项目中,我有一个 Canvas,我在其中做一些绘图。按照窗口的代码:
<Window x:Name="PropertyDefinition_Window" x:Class="PushOverStraus7.PropertyDefinitionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PropertyDefinitionWindow" Height="360" Width="730" Loaded="Window_Loaded">
<Grid>
<TreeView SelectedItemChanged="Treeview_PropertyDefinition_SelectedItemChanged">
<TreeViewItem IsExpanded="True">
<TreeViewItem />
</TreeViewItem>
<TreeViewItem>
<TreeViewItem"/>
</TreeViewItem>
</TreeView>
<Canvas x:Name="Canvas_LongitudinalBarRectanglePage" HorizontalAlignment="Left" Height="251" Margin="255,10,0,0" VerticalAlignment="Top" Width="285" Background="Black">
</Canvas>
<Button x:Name="NewButton" Content="Nuovo" HorizontalAlignment="Left" Margin="22,277,0,0" VerticalAlignment="Top" Width="45" Click="NewButton_Click"/>
<Button x:Name="DuplicateButton" Content="Duplica" HorizontalAlignment="Left" Margin="85,277,0,0" VerticalAlignment="Top" Width="45"/>
</Grid>
我想要这样,调整窗口大小,Canvas 大小会相应改变。然后,我需要调整 Canvas 的 ActualWidth 和 ActualHeight 的大小以使用它们来绘制算法。
如何自动调整 Canvas 的大小以及如何获取上述值?
感谢您的帮助
编辑: 我已按要求更改了问题
【问题讨论】:
-
请同时显示您设置框架内容的代码。为什么你需要一个框架呢?您似乎没有使用框架导航。
-
Frame 展示起来不太有用,因为它不会影响 Canvas 的行为。正如您在我的编辑中所读到的那样,我从页面(以及因此从框架)中删除了画布,因此画布显然位于窗口内,具有定义的宽度和高度
-
也许您将问题简化为您实际在做什么。删除那些不再相关的东西,并请添加相关的代码隐藏部分。