具有“按钮”外观的 WPF 复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1064658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF CheckBox with "Button" appearance
提问by Nelson Reis
I need a button-like control that can have a Checked property, so that when clicked it stays pressed.
我需要一个类似按钮的控件,它可以具有 Checked 属性,以便在单击时保持按下状态。
I had that functionality in WinForms, with the CheckBox control, setting the Appearance property to "Button".
我在 WinForms 中有这个功能,使用 CheckBox 控件,将 Appearance 属性设置为“Button”。
Can someone help me?
有人能帮我吗?
回答by rmoore
Use a ToggleButton, it has all the functionality you see in a CheckBox since it is derived from it.
使用ToggleButton,它具有您在 CheckBox 中看到的所有功能,因为它是从它派生的。
回答by Tony Borres
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.
WPF 具有用于此目的的内置 ToggleButton 控件。如果需要更改此默认控件的视觉外观,则需要对其应用新模板 (ControlTemplate)。
回答by Nit
<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>