I want a button that
我想要一个按钮
- Displays an image with NO border, NO background, NO text
- If I tab into the imagebutton, THEN it shows the background and border
- Also if I hover over it, it shows the background and border
显示无边框,无背景,无文字的图像
如果我选中图像按钮,那么它会显示背景和边框
此外,如果我将鼠标悬停在它上面,它会显示背景和边框
I've searched and I've tried so many different things, but nothing it exactly what I want. I've tried setting various properties on the button to make the background and border transparent, but it still shows up. I've tried a style with a custom control template. I'd rather not have to completely reinvent all the triggers etc to get the button to render on mouse over. The biggest problem with custom control template is that then I loose all existing functionality and I'm basically building a new control from the ground up.
我已经搜索过了,我尝试了很多不同的东西,但这完全不是我想要的东西。我尝试在按钮上设置各种属性,使背景和边框透明,但它仍然显示出来。我尝试过使用自定义控件模板的样式。我宁愿不必完全重新发明所有的触发器等,以便在鼠标悬停时渲染按钮。自定义控件模板的最大问题是,我放弃了所有现有功能,而我基本上是从头开始构建一个新控件。
Here is another link that came closest to what I wanted but it doesn't properly work for me.
这是另一个最接近我想要的链接,但它不适合我。
How do you completely remove the button border in wpf? - BUT.... for some reason the hover effect gets stuck. One I mouse over the image and the button border draws, it stays stuck on until I click somewhere else.
你如何完全删除wpf中的按钮边框? - 但是......由于某些原因,悬停效果卡住了。一个鼠标悬停在图像上并且按钮边框绘制,它一直停留在我点击其他地方之前。
1 个解决方案
#1
0
Actually, you will want to override the control template. You're not "losing" any functionality (aside from the UI triggers).
实际上,您将要覆盖控件模板。你没有“失去”任何功能(除了UI触发器)。
Original/Default Template -- This is a good starting point... copy/paste that into you're XAML (wherever you want to style this button... ie Button resources, UserControl/Window resources, App Resources?). From there make your adjustments.
原始/默认模板 - 这是一个很好的起点...将它复制/粘贴到您的XAML中(无论您想要设置此按钮的样式...即按钮资源,UserControl / Window资源,应用程序资源?)。从那里进行调整。
Another easy way is to use Expression Blend. You can easily create a new template based on the existing template, and the styling/authoring tools it provides are much better than hand-coding XAML (unless you're good at doing that).
另一种简单的方法是使用Expression Blend。您可以根据现有模板轻松创建新模板,它提供的样式/创作工具比手动编码XAML要好得多(除非您擅长这样做)。
As far as displaying an image instead of text, just set the image as the content. A Button is a type of ContentControl which means that it can house any type of content (Object
).
至于显示图像而不是文本,只需将图像设置为内容即可。 Button是一种ContentControl,这意味着它可以容纳任何类型的内容(Object)。
#1
0
Actually, you will want to override the control template. You're not "losing" any functionality (aside from the UI triggers).
实际上,您将要覆盖控件模板。你没有“失去”任何功能(除了UI触发器)。
Original/Default Template -- This is a good starting point... copy/paste that into you're XAML (wherever you want to style this button... ie Button resources, UserControl/Window resources, App Resources?). From there make your adjustments.
原始/默认模板 - 这是一个很好的起点...将它复制/粘贴到您的XAML中(无论您想要设置此按钮的样式...即按钮资源,UserControl / Window资源,应用程序资源?)。从那里进行调整。
Another easy way is to use Expression Blend. You can easily create a new template based on the existing template, and the styling/authoring tools it provides are much better than hand-coding XAML (unless you're good at doing that).
另一种简单的方法是使用Expression Blend。您可以根据现有模板轻松创建新模板,它提供的样式/创作工具比手动编码XAML要好得多(除非您擅长这样做)。
As far as displaying an image instead of text, just set the image as the content. A Button is a type of ContentControl which means that it can house any type of content (Object
).
至于显示图像而不是文本,只需将图像设置为内容即可。 Button是一种ContentControl,这意味着它可以容纳任何类型的内容(Object)。