How to create an image-button

我的梦境 提交于 2019-12-12 10:19:04

问题


I create an image-button using below code:



ImageBrush btnBrush1 = new ImageBrush();
 btnBrush1.Stretch = Stretch.Uniform;

btnBrush1.ImageSource = new BitmapImage(new Uri("ms-appx:/Images/icon_LogIn.png"));

btnLogIn.Background = btnBrush1;



The problem:

1) When using a mouse hovering the img-button, it turn grey background and icon disappear ( when not hovering the img-button, this image button is visible.

I want this image-button visible when hovering it or pressing it.

Thanks


回答1:


You need to set Image as Content rather than setting ImageBrush as Background.
Try this

Image img=new Image();
img.Source=new BitmapImage(new Uri("/Images/icon_LogIn.jpg",UriKind.RelativeOrAbsolute));
btnLogIn.Content = img;


来源:https://stackoverflow.com/questions/20321492/how-to-create-an-image-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!