如何创建图像按钮 [英] How to create an image-button

查看:22
本文介绍了如何创建图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码创建了一个图像按钮:

<前>ImageBrush btnBrush1 = new ImageBrush();btnBrush1.Stretch = Stretch.Uniform;btnBrush1.ImageSource = new BitmapImage(new Uri("ms-appx:/Images/icon_LogIn.png"));btnLogIn.Background = btnBrush1;

问题:

1) 鼠标悬停在 img-button 上时,背景变为灰色,图标消失(不悬停 img-button 时,此图像按钮可见.

我希望这个图像按钮在悬停或按下时可见.

谢谢

解决方案

您需要将 Image 设置为 Content 而不是将 ImageBrush 设置为 Background.
试试这个

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

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

解决方案

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;

这篇关于如何创建图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆