31

I need a button-like control that can have a Checked property, so that when clicked it stays pressed.

I had that functionality in WinForms, with the CheckBox control, setting the Appearance property to "Button".

Can someone help me?

3 Answers 3

52

Use a ToggleButton, it has all the functionality you see in a CheckBox since it is derived from it.

2
  • 2
    Wow! You opened a new door for me. I'm new to WPF, and didn't knew that there are hidden controls that aren't visible in the VS Toolbar. I've also found the RepeatButton that will help in another situation. Thank you so very much. Jun 30, 2009 at 16:40
  • 4
    There's lots of other stuff that you won't find in the designer, like ItemsControl. As you get more comfortable with WPF you'll probably find yourself just writing the XAML by hand or using Blend. Also, if you're brand a really good book to get is WPF Unleashed: amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/…
    – rmoore
    Jun 30, 2009 at 17:01
5

WPF has a built-in ToggleButton control that serves this purpose. If you need to change the visual appearance of this default control you will need to apply a new Template (ControlTemplate) to it.

1

<Window.BindingGroup>
    <BindingGroup Name="{x:Null}" NotifyOnValidationError="False" />
</Window.BindingGroup>
<Grid>
    <nit:checkbutton1 x:Name="button1" Margin="32,88,0,0" Click="checkbutton1_Click" HorizontalAlignment="Left" Width="31" Height="32" VerticalAlignment="Top" mode="{Binding ElementName=cb1, Path=SelectedItem}"  />
    <ComboBox x:Name="cb1" ItemsSource="{Binding Source={StaticResource modeEnum}}" IsSynchronizedWithCurrentItem="True" Height="23" Margin="0,97,24,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="112" />
 </Grid>

2
  • <Window.Resources> <ObjectDataProvider x:Key="modeEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="nit:checkmode"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources>
    – Nit
    Oct 18, 2010 at 5:07
  • What about your "nit:checkbutton1"? Oct 26, 2010 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.