如何将扩展器控件的切换按钮图标更改为“”和“-”而不是箭头
我想将扩展器控件的切换按钮图标更改为“+”和“-”而不是箭头...我尝试用 Blend 做同样的事情...但我无法做到这一点。任何人都可以帮助实现这一目标...
I want to change the icon of the expander control's toggle button icon to "+" and "-" instead of an arrow... I have tried doing the same with Blend... But I am unable to do that. Can anyone help in acheiving this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要编辑几层深度的模板。
1) 在 Blend 中,选择 Expander >编辑模板>编辑副本
这将创建扩展器样式,但会打开样式内的“扩展器模板”。
2) 打开 DockPanel 并找到“HeaderSite”切换按钮。再次选择编辑模板>编辑副本。
这将创建一个切换按钮样式并打开“切换按钮模板”进行编辑。
3) 打开边框内的网格并找到“箭头”和“圆圈”路径。您需要将它们替换为所需的图形。
我目前不确定是什么导致箭头翻转。我认为它应该是视觉状态,但它们似乎没有在模板中设置。话虽这么说,我的猜测是您会想要使用视觉状态来控制在什么时间显示哪个图像。由于这是一个 ToggleButton,请检查“已选中”和“未选中”状态。
编辑:扩展器模板中的 HeaderSite ToggleButton IsChecked 属性正在驱动箭头的翻转。它的值是绑定到父级的 IsExpanded 属性的模板。 ToggleButton 样式有一个 ControlTemplate 触发器,当 IsChecked 为 True 时,该触发器会覆盖箭头 Path 的 Data 属性。
如果您按照自己的意愿替换箭头属性,则需要替换此功能。我仍然认为视觉状态比 ControlTemplate 触发器更可取。
You'll need to edit templates a couple of layers deep.
1) In Blend, select the Expander > Edit Template > Edit a Copy
This will create an Expander Style, but will open the "Expander Template" inside the Style.
2) Open the DockPanel and locate the "HeaderSite" ToggleButton. Again, select Edit Template > Edit a Copy.
This will create a ToggleButton Style and open the "ToggleButton Template" for editing.
3) Open the Grid inside the Border and locate the "arrow" and "circle" paths. You will need to replace these with the desired graphics.
What I am uncertain of at the moment is what causes the arrow to flip. I assumed it would have been Visual State, but they don't appear to be set in the template. That being said, my guess is that you will want to use Visual States to control which image you are showing at what time. Since this is a ToggleButton, check out the Checked and Unchecked states.
EDIT: The HeaderSite ToggleButton IsChecked property in the Expander Template is driving the flipping of the arrow. Its value is template bound to the parent's IsExpanded property. The ToggleButton Style has a ControlTemplate Trigger that overrides the Data property of the arrow Path when IsChecked is True.
If you replace the arrow property, as you want to do, you'll need to replace this functionality. I still think Visual States would be preferable to the ControlTemplate Trigger.