使用ContentPresenter来个性化模板

时间:2013-02-22 08:51:05

标签: c# wpf xaml contentpresenter

我创建了一个用于创建templateButton的ressourceDictionnary。 我希望能够在使用此模板时更改png图像,我想我需要使用ContentPresenter,但我不知道为什么。

这是我的RessourceDictionnary:

 <ControlTemplate TargetType="{x:Type Button}" x:Key="BoutonRessources">
<Button Width="32" Margin="0,0,7,0" Name="tbrClear" ToolTip="Clear" VerticalAlignment="Center" BorderThickness="0" HorizontalAlignment="Center" Background="Transparent" HorizontalContentAlignment="Center">

        <Border>

            <Image Source="xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png" Height="18"/>

        <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="Background" Value="Transparent" />
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="BoutonToolbarSelected.png"/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Height"  Value="22"/>
                            <Setter Property="Width"  Value="32"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
</Button>

所以,当我使用这个Button模板时,我希望能够传递另一个png图像来显示。例如,我想用MyPicture.png替换xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png。

怎么做?使用contentPresenter?

谢谢:)

0 个答案:

没有答案