0
我正在學習WPF。比如我想畫圓圈。我可以這樣:WPF內容覆蓋
private const ushort _operatorRadius = 50;
public MainWindow()
{
var _canvas = new Canvas();
var _operatorEllipse = new Ellipse();
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
// Describes the brush's color using RGB values.
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromArgb(255, 255, 255, 0);
_operatorEllipse.Fill = mySolidColorBrush;
_operatorEllipse.StrokeThickness = 1;
_operatorEllipse.Stroke = Brushes.Black;
// Set the width and height of the Ellipse.
_operatorEllipse.Width = _operatorRadius;
_operatorEllipse.Height = _operatorRadius;
_canvas.Children.Add(curOperElips);
this.Content = _canvas;
}
但this.Content = _canvas;將覆蓋Windows的內容,然後我不能使用可視化編輯器和MainWindow.xaml。如何結合他們?
不太清楚你問什麼;您可以使用XAML代替代碼進行繪製;雖然您的窗口只能有一個內容,但您可以將該內容製作爲網格,堆疊面板,DockPanel等容器;然後他們可以託管許多物品或更多的容器。 – andrew