Wpf 图像按钮?

发布于 2024-08-04 21:06:28 字数 520 浏览 0 评论 0原文

我创建了一个具有许多按钮的 WPF 应用程序。

现在客户想将所有按钮更改为图标。 例如: 所有“确定”按钮应具有相同的图标,所有“取消”按钮应具有相同的图标,依此类推。

我想放入所有按钮 Style="{StaticResource ButtonStyle_OK}"、Style="{StaticResource ButtonStyle_OK}" 等。

现在我的问题是,我必须在这些样式中放置什么,

<Style x:Key="ButtonStyle_OK" TargetType="Button">
    <!-- What comes here? -->                
</Style>

我担心我要更改我的应用程序中的所有按钮都设置为 Image 并使用 MouseDown 事件进行单击,这会很愚蠢吗?

笔记: 我希望按钮是一个图像 - 而不是包含图像的按钮(即我不想要原始的按钮框架),谈论形状。 我想让这些按钮/样式可重复使用。

I created a WPF application that has many buttons.

Now the customer wants to change all the buttons to icons.
For example:
All the OK buttons should have the same icon, all the cancel btns and so on.

I want to put in all the buttons Style="{StaticResource ButtonStyle_OK}", Style="{StaticResource ButtonStyle_OK}" etc.

Now my question is in general what do I have to place in these styles

<Style x:Key="ButtonStyle_OK" TargetType="Button">
    <!-- What comes here? -->                
</Style>

I am affraid I am going to change all the buttons in my application to Image and use MouseDown event for click, would that be stupid?

NOTES:
I want the buttons to be an image - not a button that contains an image (i.e. I don't want the original button frame), talking about the shape.
I want to have these buttons/styles reusable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2024-08-11 21:06:28

将它们放入资源字典中,然后您所要做的就是交换字典以更改样式以及与按钮的 UI 侧相关的几乎所有内容等。

我认为您需要在标签中使用控件模板( s),类似这样:

<Setter TargetType="{x:Type Button}">
     <Setter Property="Template">
         <Setter.Value>
             <ControlTemplate TargetType="{x:Type Button}">
             </ControlTemplate>
         </Setter.Value>
     <Setter Property="Template">
</Setter>

您应该能够相对容易地在线找到默认模板(MSDN)。
我建议使用 Blend 来做到这一点(如果可以的话)——它可以让事情变得更容易。

put them into a resource dictionary, then all you have to do is swap out dictionaries to change the style and pretty much anything to do with the UI side of the buttons, etc.

I'm thinking you want a control template in the tag(s), something like this:

<Setter TargetType="{x:Type Button}">
     <Setter Property="Template">
         <Setter.Value>
             <ControlTemplate TargetType="{x:Type Button}">
             </ControlTemplate>
         </Setter.Value>
     <Setter Property="Template">
</Setter>

you should be able to find the default template online (MSDN) relatively easy.
I would recommend using Blend to do this (if you can)--it can make things hella easier.

温柔嚣张 2024-08-11 21:06:28

请查看这篇关于样式的 MSDN 文章 - http://msdn.microsoft。 com/en-us/library/ms745683.aspx

我认为您可以通过阅读 ControlTemplate 部分获得一些吸引力。

此外,正如 Chris 所指出的,样式可以进入资源字典,然后可以通过省略键来全局应用到所有按钮。

更新:您不需要将图像与单击事件一起使用,使用 ControlTemplate 将允许您更精确地定义按钮的外观。

另一个例子 - http://mrpmorris.blogspot.com/2008 /04/wpf-custom-button-templates.html

Take a look at this MSDN article on styling - http://msdn.microsoft.com/en-us/library/ms745683.aspx

I think you might be able to get some traction by reading the ControlTemplate section.

Also, as noted by Chris, the styles can go into a resource dictionary and then can be applied globally against all buttons by omitting a key.

UPDATE: You will not need to use image with click event, using the ControlTemplate will allow you to define the look of the button more precisely.

Another example - http://mrpmorris.blogspot.com/2008/04/wpf-custom-button-templates.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文