C# 在windows phone应用程序中更改按钮图像

C# 在windows phone应用程序中更改按钮图像,c#,windows-phone,C#,Windows Phone,我想在单击按钮时更改按钮图像。以下是我的xaml代码: <Button x:Name="bt1" HorizontalAlignment="Left" Click="OnClick" ClickMode="Press" Foreground="Red" Width="294" > <StackPanel> <Image Name="Image" Source="/./Assets/RegIcons/ovenc.png" Height="80"

我想在单击按钮时更改按钮图像。以下是我的xaml代码:

<Button x:Name="bt1"

        HorizontalAlignment="Left" Click="OnClick" ClickMode="Press" Foreground="Red" Width="294"  >

<StackPanel>
<Image Name="Image" Source="/./Assets/RegIcons/ovenc.png" Height="80" Width="80"/>
您需要将此位图图像分配给图像控件


其中Image是图像控件的名称

我没有使用单独的图像控件,而是将按钮的Background属性设置为Image

以下是XAML代码:

<Button x:Name="bt1" Height="150" Content="click" Click="OnClick">

在通用应用程序Blank应用程序中,它对我有效

bt1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("ms-appx:/Assests/RegIcons/tvc.png", UriKind.RelativeOrAbsolute)) };

<Button x:Name="bt1" Height="150" Content="click" Click="OnClick">
        private void OnClick(object sender, RoutedEventArgs e)
        {
            bt1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("/Assests/RegIcons/tvc.png", UriKind.Relative)) };
        }
bt1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("ms-appx:/Assests/RegIcons/tvc.png", UriKind.RelativeOrAbsolute)) };
            BitmapImage bmp = new BitmapImage();
            Uri u = new Uri("ms-appx:/Images/timer.png", UriKind.RelativeOrAbsolute);
            bmp.UriSource = u;
            // NOTE: change starts here
            Image i = new Image();
            i.Source = bmp;
            button1.Content = i;