如何在WPF中的UserControl中使用Canvas

时间:2015-07-04 13:19:53

标签: c# wpf

我想在WPF中的UserControl中使用Canvas但是

中没有任何Canvas
public partial class UserControl1 : UserControl

我想将第二个userControl更改为Canvas
我该怎么办? 尊重

1 个答案:

答案 0 :(得分:1)

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

enter image description here

<强>更新

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>