C# WPF自定义控件和模板继承

C# WPF自定义控件和模板继承,c#,wpf,xaml,templates,custom-controls,C#,Wpf,Xaml,Templates,Custom Controls,我很难找到如何继续使用ImageButton模板 简单操作:通过遵循本教程,我创建了一个新的customControl ImageButton: 到目前为止,一切都很好,效果很好 但是,在我的应用程序中,我有不同的按钮主题(在应用程序开始时就知道)。我的不同按钮主题是这样定义的: <Style x:Key="MONDE0_ImageActionButton" TargetType="Button"> <Setter Property="Template">

我很难找到如何继续使用ImageButton模板

简单操作:通过遵循本教程,我创建了一个新的customControl ImageButton:

到目前为止,一切都很好,效果很好

但是,在我的应用程序中,我有不同的按钮主题(在应用程序开始时就知道)。我的不同按钮主题是这样定义的:

<Style x:Key="MONDE0_ImageActionButton" TargetType="Button">

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Name="BaseBorder" CornerRadius="5" BorderThickness="1" BorderBrush="Black" Background="{DynamicResource DefaultBlueButton}">
                    <ContentPresenter VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,2,0">

                    </ContentPresenter>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="BaseBorder" Property="Background" Value="{StaticResource DefaultOverBlueButton}" />
                    </Trigger>
                    <Trigger Property="Button.IsPressed" Value="True">
                        <Setter TargetName="BaseBorder" Property="Background" Value="{StaticResource DefaultClickedBlueButton}" />
                    </Trigger>
                </ControlTemplate.Triggers>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

问题是,当我尝试通过以下方式将此主题应用于我的imgButton时:

<VegaCtr:ImageButton x:Name="btn_Send" Margin="5" Style="{DynamicResource MONDE0_actionButton}" Width="105" Height="40" ToolTip="Envoyer" Command="{Binding SendCommand}"
            Image="pack://application:,,,/Vega_WPF_Themes;component/Themes/Common/Images/Yes.png" Content="Valider"/>

我的imagebutton样式

<Style TargetType="{x:Type local:ImageButton}" x:Name="StyleImgButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ImageButton}">
                <!-- Button Content -->
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                    <Image Source="{TemplateBinding Image}" Visibility="{TemplateBinding Image, Converter={StaticResource VisibilityConvertor}}"
                             Width="{TemplateBinding ImageWidth}" Height="{TemplateBinding ImageHeight}" Margin="0,0,5,0" />
                    <TextBlock Text="{TemplateBinding Content}" Style="{StaticResource buttonLabel}" TextWrapping="Wrap" />
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

imageButton的基本模板不起作用。当我删除样式属性时,它会起作用。。。所以,我的问题是,我怎样才能让它起作用?我需要有基本的imageButton模板,并可能添加我的其他样式(带有触发器等)。 这可能吗


谢谢

在样式上使用basedOn属性来设置基本样式

<Style x:Key="MONDE0_ImageActionButton" TargetType="Button" BasedOn="{StaticResource "My_BaseStyle"}>

它不起作用,因为ImageButton的样式指向一个ImageButton,它是按钮的继承。我添加了样式imgbutton样式以使其更清晰(非常接近codeproject上的样式)