使用MahApps Metro点击按钮后更改图像

时间:2015-07-25 13:02:17

标签: wpf button mahapps.metro

我正在使用MahApps Metro,这是我的Button

<Button
    Name="startBtn"
    Width="55"
    Height="55"
    VerticalAlignment="Top"
    Style="{DynamicResource MetroCircleButtonStyle}"
    Click="playBtn_Click">
    <Rectangle
      Width="25"
      Height="25">
        <Rectangle.Fill>
            <ImageBrush                         
                ImageSource="pack://application:,,,/Resources/start.ico" />
        </Rectangle.Fill>
    </Rectangle>
</Button>

所以我想改变Button内的image Button Click Event

private void startBtn_Click(object sender, RoutedEventArgs e)
{

}

1 个答案:

答案 0 :(得分:0)

XAML:

<Button
   Name="startBtn"
   Width="55"
   Height="55"
   VerticalAlignment="Top"
   Style="{DynamicResource MetroCircleButtonStyle}"
   Click="playBtn_Click">
   <Image Width="25" Height="25" Source="pack://application:,,,/Resources/start.ico" />
</Button>

代码:

private void startBtn_Click(object sender, RoutedEventArgs e)
{
     ((sender as Button).Content as Image).Source = new BitmapImage(new Uri("yourpath.png"));
}