Wpf 将第二个图像添加到按钮的内容

Wpf 将第二个图像添加到按钮的内容,wpf,button,datatemplate,Wpf,Button,Datatemplate,这是按钮的和平代码: <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" CornerRadius="8"> <Border.Background> SlateBlue </Border.Background>

这是按钮的和平代码:

<Button.Template>
    <ControlTemplate TargetType="{x:Type Button}">
        <Border x:Name="border" CornerRadius="8">
            <Border.Background>
                SlateBlue
            </Border.Background>
            <StackPanel Orientation="Horizontal" Margin="3">
                <Image Source="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Height="30" Width="30" Stretch="Fill" Margin="0 0 0 0" />
                <TextBlock Text="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" FontSize="12" VerticalAlignment="Center" Padding="10,0,10,0" />                    
            </StackPanel>
        </Border>
    </ControlTemplate>
</Button.Template>
<myProject:ButtonWithTwoImages x:Name="btnHome" Tag="/Resources/Home.png" Content="Home" Command="{Binding Path=NavigateToCategoriesCommand}" Margin="20 0 0 0"/>

石板蓝
正如你所看到的,我的按钮有一个图像和一个文本。但是,我想在文本之后添加另一个图像。我该怎么做?我已经使用过Tag属性一次

下面是我如何使用按钮:

<Button.Template>
    <ControlTemplate TargetType="{x:Type Button}">
        <Border x:Name="border" CornerRadius="8">
            <Border.Background>
                SlateBlue
            </Border.Background>
            <StackPanel Orientation="Horizontal" Margin="3">
                <Image Source="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Height="30" Width="30" Stretch="Fill" Margin="0 0 0 0" />
                <TextBlock Text="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" FontSize="12" VerticalAlignment="Center" Padding="10,0,10,0" />                    
            </StackPanel>
        </Border>
    </ControlTemplate>
</Button.Template>
<myProject:ButtonWithTwoImages x:Name="btnHome" Tag="/Resources/Home.png" Content="Home" Command="{Binding Path=NavigateToCategoriesCommand}" Margin="20 0 0 0"/>


如何向按钮添加另一个图像?

我创建了一个名为ButtonWithTwoImages的新用户控件,下面是代码

Xaml 如何使用它


使用资源或使用依赖项属性。有两个图像的按钮是什么?它是用户控件吗?@YuliamChandra ButtonWithTwoImages是定义按钮的文件名。该文件具有根元素按钮,其中包含上述代码中的代码。@petko_stankoski,您可以使用dependency属性
<Window x:Class="WpfUserControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mylib="clr-namespace:WpfUserControl">
    <Grid>
        <mylib:ButtonWithTwoImages Image1="Images\A.jpg" Image2="Images\B.jpg"></mylib:ButtonWithTwoImages>
    </Grid>
</Window>