在Visual Studio 2010中冻结WPF控件

时间:2012-03-11 22:06:54

标签: visual-studio-2010 wpf-controls

我在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>

1 个答案:

答案 0 :(得分:0)

可能是因为你从非usercontrol类继承了你的控件?在WPF中,第一条规则是避免控制继承。尝试使用合成