将图标放在居中按钮旁边的最简单方法是什么?

What is the easiest way to put an icon beside a centered button?

我有一个按钮和一个图标 :

<Button Content="Hello" Click="MyHandler"/>
<Image Source="icon.ico"/>

我希望按钮位于其容器的中央,图标位于其旁边,如下所示:

无论屏幕大小如何,按钮与其图标之间的距离应保持相同。

我尝试了 GridStackPanel,但我无法得到正确的结果。

我怎样才能做到这一点?

如果你想要 Button Image 的组合作为一个居中,你可以使用 StackPanel.

<StackPanel Orientation="Horizontal"
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
    <Button Content="Hello"
            Click="MyHandler"/>
    <Image Source="icon.ico"/>
</StackPanel>

如果只有 Button 居中,Image 放在它旁边,可以使用 Grid

<Grid VerticalAlignment="Center">
     <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*"/>
         <ColumnDefinition Width="Auto"/>
         <ColumnDefinition Width="*"/>
     </Grid.ColumnDefinitions>
     <Button Grid.Column="1"
             Content="Hello"
             Click="MyHandler"/>
    <Image Grid.Column="2"
           HorizontalAlignment="Left"
           Source="icon.ico"/>
</Grid>