我在工具栏中的自定义控件
我有一个具体的控制。我想在它放置在工具栏中时为其设置样式。我已经找到了如何在 Button、CheckBox 和其他标准控件中做到这一点,但是我应该如何为我的控件制作它?
I have a specific control. I want to make style for it when it is placed in ToolBar. I have found how to do it in case of Button, CheckBox and other standard controls, but how I should make it for my control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
命名空间 - 您的控件所在的位置
CustomControl - 您的控件的名称。
这是你想要的吗?
编辑:
如果您希望在控件中使用工具栏样式,只需将样式放置在用户控件资源中,它将应用于控件中放置的工具栏。此样式的范围将仅限于您的控制范围,并将隐藏在您的控制范围之外。
NameSpace - where your Control is present
CustomControl - Name of your control.
Is this what you want?
EDIT:
If you want Style for Toolbar in your control, simply place the style in your UserControl Resources, it will be applied to the Toolbar placed within your control. The scope for this style will be limited to your control and will be hidden outside your control.
好吧,现在你澄清了你的问题,我想我可以给你一个解决方案。看起来您只需为特定用户控件设置 ToolBar 控件的 ItemContainerStyle 即可。首先声明您的特定控件所在的“my”命名空间,然后添加如下内容:
如果您想向工具栏添加其他控件类型(如上面提到的按钮),那么您将需要定义一个自定义 StyleSelector,而不是您将设置为 ItemContainerStyleSelector 属性。这是 StyleSelector 实现的一个很好的示例:样式选择器< /a>
Ok now you clarified your question I think I can give you a solution. It looks like you simply need to set the ItemContainerStyle of the ToolBar control for your specific user control. First declare the "my" namespace where your specific control is located, then just add something like this:
If you wanna add other control types to the ToolBar like the Button you mentioned above, then you will need to define a custom StyleSelector instead that you will set to the ItemContainerStyleSelector property. Here is a pretty good sample of StyleSelector implementation: Style Selectors