【问题标题】:WPF CheckBox with "Button" appearance具有“按钮”外观的 WPF 复选框
【发布时间】:2010-11-07 01:42:44
【问题描述】:

我需要一个类似按钮的控件,它可以具有 Checked 属性,以便在单击时保持按下状态。

我在 WinForms 中拥有该功能,使用 CheckBox 控件,将 Appearance 属性设置为“Button”。

有人可以帮我吗?

【问题讨论】:

    标签: wpf checkbox wpf-controls


    【解决方案1】:

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

    【讨论】:

    • 哇!你为我打开了一扇新的大门。我是 WPF 的新手,不知道有隐藏控件在 VS 工具栏中不可见。我还发现了可以在另一种情况下提供帮助的 RepeatButton。非常感谢。
    • 还有很多您在设计器中找不到的其他东西,例如 ItemsControl。随着您对 WPF 越来越熟悉,您可能会发现自己只是手动编写 XAML 或使用 Blend。此外,如果您是品牌,那么一本非常好的书是 WPF Unleashed:amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/…
    【解决方案2】:

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

    【讨论】:

      【解决方案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>
      

      【讨论】:

      • 你的“nit:checkbutton1”呢?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多