2009-06-30 90 views
26

我需要一个可以具有Checked属性的按钮式控件,以便在单击时保持按下状态。带有“按钮”外观的WPF复选框

我在WinForms中使用CheckBox控件将Appearance属性设置为“Button”。

有人可以帮助我吗?

回答

40

使用ToggleButton,它具有您在CheckBox中看到的所有功能,因为它是从它派生的。

+1

哇!你为我开了一扇新门。我是WPF的新手,并不知道在VS工具栏中没有隐藏的控件。我还发现了RepeatButton,这将有助于另一种情况。非常感谢你。 – 2009-06-30 16:40:55

+4

有很多其他的东西,你不会在设计器中找到,比如ItemsControl。随着您对WPF更加熟悉,您可能会发现自己只需手动编写XAML或使用Blend即可。此外,如果你是品牌真正好书是WPF释放:http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917 – rmoore 2009-06-30 17:01:59

5

WPF有一个内置的ToggleButton控件用于此目的。如果您需要更改此默认控件的外观,您需要为其应用新的模板(ControlTemplate)。

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>