当您尝试将其构建到布局中时,画布似乎与其他元素很好地协同工作,控制侧和画布是绘图区域。如何将画布合并到WPF中的较大布局中?
例如,为什么我可以在除画布之外的每个元素上放一个边框?在下面的代码,边境线画布,但在画布只在顶部有,但不是在左侧,右侧或底部边框:
<Window x:Class="WpfApplication25.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel>
<TextBlock DockPanel.Dock="Bottom" Text="Move the slider to reveal the answer:"/>
<Slider DockPanel.Dock="Bottom" Name="theSlider"
HorizontalAlignment="Left"
Width="200"
Minimum="0"
Maximum="1"
Value="1"
Cursor="Hand"/>
<Border BorderBrush="Tan" BorderThickness="2">
<Canvas>
<TextBlock Canvas.Left="45" Canvas.Top="50" Text="test" FontSize="16"/>
<Rectangle
Canvas.Left="10"
Canvas.Top="10"
Width="100"
Height="100"
Fill="Silver"
Opacity="{Binding ElementName=theSlider, Path=Value}"
/>
</Canvas>
</Border>
</StackPanel>
</Window>
是的,我给它一个高度和宽度,然后边框围绕画布,但有一个奇怪的边距。看起来,canvas与其他元素有着奇怪的关系,希望看到一个WPF中使用Canvas的例子,其中包含控件,等等。 – 2009-02-12 14:13:51