设置按钮样式以匹配 TreeView 上展开/折叠按钮的当前主题

发布于 2024-09-28 09:16:56 字数 601 浏览 2 评论 0原文

如您所知,内置主题都为标准控件(例如 TreeView 控件)定义了样式。我们正在尝试创建一些看起来非常像 TreeView 但实际上不是 TreeView 的东西,也不是 TreeView 的子类。它只是有一些我们希望看起来像的部分,以保持一致性。

例如,我们的控件也有一个选定项目,我们希望其背景与当前主题的 TreeView(或更准确地说是 TreeViewItem)中选定项目的背景外观相匹配。 (您不能简单地使用突出显示颜色,因为主题具有漂亮的渐变画笔和边框,而不仅仅是实心画笔。)与我们的展开/折叠切换按钮相同。我们希望它们看起来就像当前主题的 TreeView 中使用的一样。 (即有时是一个三角形,有时是一个带有“+”的方框,等等。)

现在,虽然我们可以简单地打开表达式并自己复制样式(或者至少是我们需要的部分),但我们必须这样做对于 MS 提供的每个主题。另外,这无法处理较新的主题。从最纯粹的角度来看,这是重复的样式信息,这对我来说是错误的。

另外,如果有人对实际的 TreeView(Item) 进行样式设置,我们也想选择它。由于我们想要设置样式的部分是 TreeView 的必需部分,因此我们非常有信心它们在样式方面位于某个位置。

甚至不确定我想做的事情是否可能,但如果有人知道,他们很可能就在这里!

As you know, the built-in themes all define styles for the standard controls such as the TreeView control. We're trying to create something that looks an awful lot like a TreeView but isn't actually one, nor is it a subclass of one. It just has parts that we want to look like one for consistency.

For instance, our control too has a selected item whose background we'd love to match to the appearance of the background for the selected item in a TreeView (or more accurately the TreeViewItem) for the current theme. (You can't simply use highlight color as the themes have nice gradient brushes and borders, not just a solid brush.) Same with our expand/collapse togglebuttons. We want them to look just like the ones used in a TreeView for the current theme. (i.e. Sometimes a triangle, sometimes a box with a '+' in it, etc.)

Now while we can simply rip open Expression and copy the styles ourselves (or at least the parts that we need), we'd have to do that for each and every theme that MS provides. Plus, that wouldn't handle newer themes. And in a purest standpoint, that's duplicate styling information which just sits wrong with me.

Also, if someone styles the actual TreeView(Item), we want to pick it up as well. Since the parts that we want to style are required parts of a TreeView, we feel pretty confident that they're in there somewhere style-wise.

Not even sure what I want to do is possible but if anyone knows, they're most likely here on SO!

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

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

发布评论

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

评论(1

〃安静 2024-10-05 09:16:56

又一个问题近一个月了,甚至没有评论。 SO 社区至少一次没有插话,这很奇怪!估计不可能吧

好吧,我们最终做的是使用“向我展示模板”(Google it)来获取该部分的模板(我们没有表达式),然后自己手动管理它们,而不是使用内置样式。这根本不是我们想要做的,因为我们不知道如何获得系统中已经定义的漂亮渐变而不重复它们,但最终结果确实完美匹配,所以就是这样。因此,这也被标记为答案。如果其他人确实给了我一个有效的(或者足够接近的),我会很乐意更改它!只需要一些东西人!感觉就像我在真空中发帖一样!

Yet another question close to a month old without even a comment. Very odd for the SO community to not chime in at least once! Guess it's not possible.

Well, what we ended up doing was using 'Show Me The Template' (Google it) to get the templates for the part (we don't have Expression), then manually managing them ourselves instead of using the built-in styles. NOT at all what we wanted to do since we don't know of a way to get the nice gradients that are defined in the system already without duplicating them, but the end result does match perfectly so there's that. As such, this too is getting marked as the answer. I'll gladly change it if someone else actually gives me one that works (or is close enough! Just need something people! Feel like I'm posting in a vacuum here!

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