Visual studio 2010 WPF控件在Visual Studio 2010中冻结

Visual studio 2010 WPF控件在Visual Studio 2010中冻结,visual-studio-2010,wpf-controls,Visual Studio 2010,Wpf Controls,我在WPF中做了一个自定义按钮控件,并试图在WinForms(c#)中实现它。现在,该控件工作正常,编译良好,但我似乎无法访问elementhost-该控件未显示在工具箱中,后来我看到它被冻结,即,我无法将其添加到表单中。由于项目构建过程没有出现错误或警告,我不知道是什么导致了问题。任何帮助都将不胜感激,谢谢 编辑:以下是xaml文件的代码: <Button x:Class="proba4.UserControl1" xmlns="http://schemas.m

我在WPF中做了一个自定义按钮控件,并试图在WinForms(c#)中实现它。现在,该控件工作正常,编译良好,但我似乎无法访问elementhost-该控件未显示在工具箱中,后来我看到它被冻结,即,我无法将其添加到表单中。由于项目构建过程没有出现错误或警告,我不知道是什么导致了问题。任何帮助都将不胜感激,谢谢

编辑:以下是xaml文件的代码:

<Button x:Class="proba4.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="120" d:DesignWidth="300" IsEnabled="True">
    <Button.Template>
        <ControlTemplate TargetType="{x:Type Button}">
            <Grid>
                <Image Name="Normal" Source="C:\stuff\off_button.gif"/>
                <Image Name="Pressed" Source="C:\stuff\on_button.gif" Visibility="Hidden"/>

            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
                </Trigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Button.Template>
</Button>


可能是因为您从非usercontrol类继承了控件?在WPF中,第一条规则是避免控件继承。试着用作文

我想过,但我没有作文方面的经验。有什么建议吗?没关系,我做了;非常感谢)。代码将类似于您的代码,但在第1行中,用UserControl标记替换Button标记,并将标记添加到其内容中