views:

1611

answers:

4

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?

+7  A: 

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

rmoore
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
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
+2  A: 

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
A: 

<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
<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
What about your "nit:checkbutton1"?
Nelson Reis