请问下我在WPF里面怎设置点击butooin改变butooin的背景图片啊?

<Button Canvas.Left="159" Canvas.Top="87" Height="35" Name="button2" Width="36" IsCancel="False" Click="button2_Click">
               <Image Source="/WpfApplication1;component/bin/Debug/结束.png"></Image>
            </Button>

//停止服务
       private void button2_Click(object sender, RoutedEventArgs e)
       {
           Uri uri = new Uri("结束-灰色.png", UriKind.Relative);
           BitmapImage bimg = new BitmapImage(uri);
           button2.Background = new ImageBrush(bimg);
       }



现在我在Click事件里面写没效果?


慕神8447489
浏览 515回答 2
2回答

撒科打诨

&nbsp; private void button2_Click(object sender, RoutedEventArgs e)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Uri uri = new Uri("图片路径", UriKind.Relative);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BitmapImage bimg = new BitmapImage(uri);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button2.Background = new ImageBrush(bimg);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }在Windows Phone8 里面不能这样写啊!它说button2.Background = new ImageBrush(bimg);有错
打开App,查看更多内容
随时随地看视频慕课网APP