How can I apply the style of a ToolBar CheckBox to a regular CheckBox?

我们两清 提交于 2019-12-24 02:13:23

问题


I would like to style a regular CheckBox so it looks like a CheckBox inside a Toolbar:

<StackPanel Orientation="Horizontal">
  <CheckBox Style="{What to put here?}">
    <Image Source="someImage.png" Stretch="None" />
  </CheckBox>
</StackPanel>

Is there a way to obtain a reference to the Style use by the ToolBar and 'bind' to it?

EDIT: The reason for this is because I want a few simple buttons to control the Visibility of some elements and I don't want to use a ToolBar just for this.


回答1:


Never mind, I found the solution:

<StackPanel Orientation="Horizontal">
  <CheckBox Style="{StaticResource {x:Static ToolBar.CheckBoxStyleKey}}">
    <Image Source="someImage.png" Stretch="None" />
  </CheckBox>
</StackPanel>



回答2:


I think you might need to use a ToggleButton or make a control template, You might find the following urls useful:

http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.aspx WPF CheckBox with "Button" appearance



来源:https://stackoverflow.com/questions/6677156/how-can-i-apply-the-style-of-a-toolbar-checkbox-to-a-regular-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!