【问题标题】:Change image after button click using MahApps Metro使用 MahApps Metro 单击按钮后更改图像
【发布时间】:2015-07-25 13:02:16
【问题描述】:

我正在使用 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 Click Event 中更改Button image

private void startBtn_Click(object sender, RoutedEventArgs e)
{

}

【问题讨论】:

    标签: wpf button mahapps.metro


    【解决方案1】:

    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"));
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 1970-01-01
      • 2017-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 2013-11-05
      相关资源
      最近更新 更多