WPF control frozen in Visual Studio 2010

和自甴很熟 提交于 2020-01-17 02:20:16

问题


I did a custom button control in WPF and I am trying to implement it in WinForms (c#). Now, the control is working and it compiles well, but I can't seem to access the elementhost - the control was not shown in the toolbox, and afterwards I saw it's frozen, i.e. I can't add it to the form. Since the project build process went without errors or warnings, I don't know what is causing the problem. Any help would be appreciated, thanks.

EDIT: Here's the code of the xaml file:

<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:


May be it is because you inherit your control from non-usercontrol class? In WPF the first rule is avoiding control inheritance. Try to use composition



来源:https://stackoverflow.com/questions/9659350/wpf-control-frozen-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!