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?

Nelson Reis
  • 4,780
  • 9
  • 43
  • 61

3 Answers3

52

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

rmoore
  • 15,162
  • 4
  • 59
  • 59
  • 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. – Nelson Reis Jun 30 '09 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: http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917 – rmoore Jun 30 '09 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.

Tony Borres
  • 1,546
  • 11
  • 11
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>

Nit
  • 11
  • 1