如何为所有州的 Metro 应用程序设置自定义按钮背景 [英] How do I set a custom button background for a Metro app for all states

查看:28
本文介绍了如何为所有州的 Metro 应用程序设置自定义按钮背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 Metro 风格的 Windows 8 应用程序的按钮使用我自己的位图.我可以将按钮的背景画笔设置为我自己的 ImageBrush 并且效果很好,除了悬停和按下状态.我不知道如何为它们设置位图.有人知道怎么做吗?

I want to use my own bitmaps for my buttons for a Metro style Windows 8 app. I can set the background brush for a button to my own ImageBrush and that works fine, except for the hover and pressed states. I cannot figure out how to set the bitmaps for them. Does anyone know how to do this?

谢谢.

推荐答案

WinRT XAML Toolkit 有一个 ImageButton 控件如果您需要,则允许为所有状态定义图像.您还可以在 Generic.xaml 中检查其默认模板,以了解它是如何使用基于多个重叠图像控件(检查例如 PART_HoverStateImage)和控制这些图像控件不透明度的视觉状态的位图.如果您懒惰 - 您也可以仅使用两个位图并使用使用 PressedStateImageSource 定义的半透明位图,该位图覆盖在 IdleStateImageSource 定义的位图之上,以显示悬停状态.或者你可以完全懒惰,只使用一个位图作为空闲状态,让控件通过将 GeneratePressedState 和 GenerateHoverState 设置为 true 来为其他两个状态生成位图 - 通过使用一些基本图像照亮"空闲状态图像来生成这些位图加工.该工具包还有一个示例应用,其页面展示了 ImageButton 控件的多种使用方式.

WinRT XAML Toolkit has an ImageButton control that allows to define images for all states if that is what you need. You can also check its default template in Generic.xaml to see how it uses the bitmaps based on multiple overlaid Image controls (check e.g. PART_HoverStateImage) and visual states that control opacities of these Image controls. If you are lazy - you can also use just two bitmaps and use semi-transparent bitmap defined using the PressedStateImageSource overlaid on top of the bitmap defined with IdleStateImageSource to show a hover state. Or you can go fully lazy and use just a single bitmap for idle state and let the control generate bitmaps for the other two states by setting GeneratePressedState and GenerateHoverState to true - that generates these bitmaps by "lightening" the idle state image with some basic image processing. The Toolkit also has a sample app with a page that demonstrates the use of the ImageButton control in multiple ways.

这篇关于如何为所有州的 Metro 应用程序设置自定义按钮背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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