簡體   English   中英

如何在WPF中的UserControl中使用畫布

[英]How to Use Canvas in UserControl in WPF

我想在WPF中的UserControl中使用Canvas,但其中沒有任何Canvas

public partial class UserControl1 : UserControl

我想將第二個userControl更改為Canvas
我該怎么辦?
尊重地

Canvas類位於程序集PresentationFramework.dll ,因此您應添加對此程序集( msdn )的引用:

命名空間:System.Windows.Controls

程序集:PresentationFramework(在PresentationFramework.dll中)

XAML的XMLNS: http : //schemas.microsoft.com/winfx/2006/xaml/presentation,http : //schemas.microsoft.com/netfx/2007/xaml/presentation

在此處輸入圖片說明

更新

1)您應該在后面的代碼中更改此值:

public partial class UserControl1 : Canvas
{
    public UserControl1()
    {
        InitializeComponent();
    }
}

2)您應該在XAML中進行更改:

<Canvas x:Class="MyApp.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

</Canvas>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM