WPF CheckBox with “Button” appearance

十年热恋 提交于 2019-12-18 18:50:26

问题


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?


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1064658/wpf-checkbox-with-button-appearance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!