2012-03-11 67 views
0

我在WPF中做了一个自定义按钮控件,我试图在WinForms(c#)中实现它。现在,控件运行良好,但我似乎无法访问元素主机 - 控件未显示在工具箱中,之后我看到它已冻结,即我无法将其添加到表单中。由于项目构建过程没有错误或警告,我不知道是什么导致了这个问题。任何帮助将不胜感激,谢谢。在Visual Studio 2010中冻结的WPF控件

编辑:下面是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> 

回答

0

可能那是因为你继承非控件类的控制?在WPF中,第一条规则是避免控制继承。尝试使用作文

+0

我想过了,但我没有作文经验。有小费吗? – 2012-03-11 22:24:27

+0

没关系,我做到了;非常感谢你)。 – 2012-03-11 22:29:01

+0

代码将与您的代码类似,但在#1行中将Button标签替换为UserControl标签,并在其内容中添加