【发布时间】:2017-10-15 16:48:42
【问题描述】:
我在 WPF 中的画布上绘制形状时遇到了一个非常奇怪的问题。
<DockPanel Grid.Row="3">
<Canvas Name="BottomCanvas" Margin="15" Background="Yellow">
<Canvas Name="TransparentCanvas" Background="Transparent"
MouseDown="TransparentCanvas_MouseDown"
MouseUp="TransparentCanvas_MouseUp"
MouseMove="TransparentCanvas_MouseMove"
Width="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Canvas}},Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Canvas}},Path=ActualHeight}">
</Canvas>
</Canvas>
</DockPanel>
上面定义了我的画布。
下面是一个画椭圆的简单例子;我不知道为什么这没有效果。
Ellipse myEllipse = new Ellipse();
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(0, 0, 255, 0);
myEllipse.Fill = mySolidColorBrush;
myEllipse.Width = myEllipse.Height = 100;
Canvas.SetTop(myEllipse, 15);
Canvas.SetLeft(myEllipse, 15); ;
bottomCanvas.Children.Add(myEllipse);
谁能看出问题所在?
编辑:
对不起。正如您在 XAML 画布中看到的那样,名为“BottomCanvas”,在代码中我使用了bottomCanvas,这是一个添加到MainWindow 的属性,我不知道它的用途。就是这样。
【问题讨论】: