I want to make a bigger checkbox in WPF.
I've discovered that I need to d开发者_如何学Goo a control template, one example of which is found here: http://msdn.microsoft.com/en-us/library/ms752319.aspx
If I use that code the checkbox doesn't resemble the default look. All I want to do is change the Border Width & Height attributes.
I need a control template that looks exactly like the default, from there I will just change the Width and Height. Does anyone know where I can find one? Or a better approach?
How about this?
<CheckBox>
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
</CheckBox>
You can use double values for ScaleX and ScaleY if the integer values are not exactly what you want.
Here is a possible solution found on msdn:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/98cf8a65-f4ca-4ff5-9851-c2989b91a013
The default ControlTemplates can be found on MSDN (see Default WPF Themes
link).
Make sure to add the respective themes namespace to your xaml file to reference the necessary theme controls.
<theme:BulletChrome Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
RenderMouseOver="{TemplateBinding IsMouseOver}"
RenderPressed="{TemplateBinding IsPressed}"
IsChecked="{TemplateBinding IsChecked}"/>
I am not sure if you can just specify it generically, you might need to add references too.
The problem here is that you cannot really specify a border size either since the control encapsulates it.
The best solution I found is to wrap it in the ViewBox:
<Viewbox Height="46" HorizontalAlignment="Left" >
<CheckBox Content="Some Content"/>
</Viewbox>
You can use visual tree of the checkbox and when the elements you want exist, change them at runtime by explicitly setting the Width and Height. Use Peter Blois' snoop or some equivalent to see if there are named elements you can access with FindName; if not you will have to guess (e.g., some styles might have two Border elements and you must pick one) and walk the visual tree explicitly.
Keep in mind that your code should do nothing if you don't find the elements you are looking for.
精彩评论