WPF CheckBox with “Button” appearance

后端 未结 3 1923
不思量自难忘°
不思量自难忘° 2021-01-03 20:22

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

相关标签:
3条回答
  • 2021-01-03 20:43

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

    0 讨论(0)
  • 2021-01-03 20:53

    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.

    0 讨论(0)
  • 2021-01-03 20:56

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

    0 讨论(0)
提交回复
热议问题