Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
164 lines (152 sloc) 11.3 KB
<Type Name="CheckBox" FullName="System.Windows.Controls.CheckBox">
<TypeSignature Language="C#" Value="public class CheckBox : System.Windows.Controls.Primitives.ToggleButton" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi CheckBox extends System.Windows.Controls.Primitives.ToggleButton" />
<TypeSignature Language="DocId" Value="T:System.Windows.Controls.CheckBox" />
<TypeSignature Language="VB.NET" Value="Public Class CheckBox&#xA;Inherits ToggleButton" />
<TypeSignature Language="C++ CLI" Value="public ref class CheckBox : System::Windows::Controls::Primitives::ToggleButton" />
<TypeSignature Language="F#" Value="type CheckBox = class&#xA; inherit ToggleButton" />
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Windows.Controls.Primitives.ToggleButton</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.DefaultEvent("CheckStateChanged")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Windows.Localizability(System.Windows.LocalizationCategory.CheckBox)</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Represents a control that a user can select and clear.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Windows.Controls.CheckBox> controls inherit from <xref:System.Windows.Controls.Primitives.ToggleButton> and can have three states: checked (selected), unchecked (cleared), and indeterminate.
A <xref:System.Windows.Controls.CheckBox> is a <xref:System.Windows.Controls.ContentControl>, which means that it can contain a single object of any type (such as a string, an image, or a panel). For more information, see the <xref:System.Windows.Controls.ContentControl> class.
## Customizing the CheckBox Control
To apply the same property settings to multiple <xref:System.Windows.Controls.CheckBox> controls, use the <xref:System.Windows.FrameworkElement.Style%2A> property. You can modify the default <xref:System.Windows.Controls.ControlTemplate> to give the control a unique appearance. For more information about creating a <xref:System.Windows.Controls.ControlTemplate>, see [Customizing the Appearance of an Existing Control by Creating a ControlTemplate](~/docs/framework/wpf/controls/customizing-the-appearance-of-an-existing-control.md). To see the parts and states that are specific to the <xref:System.Windows.Controls.CheckBox>, see [CheckBox Styles and Templates](~/docs/framework/wpf/controls/checkbox-styles-and-templates.md).
Dependency properties for this control might be set by the control's default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see [Default WPF Themes](https://go.microsoft.com/fwlink/?LinkID=158252).
[!INCLUDE[setting-a-visual-property](~/includes/visual-property-note.md)]
## Examples
The following example creates a <xref:System.Windows.Controls.CheckBox> and handles the <xref:System.Windows.Controls.Primitives.ToggleButton.Checked>, <xref:System.Windows.Controls.Primitives.ToggleButton.Unchecked>, and <xref:System.Windows.Controls.Primitives.ToggleButton.Indeterminate> events.
[!code-xaml[CheckBox_Snippets#4](~/samples/snippets/csharp/VS_Snippets_Wpf/CheckBox_Snippets/CSharp/Window1.xaml#4)]
[!code-csharp[CheckBox_Snippets#5](~/samples/snippets/csharp/VS_Snippets_Wpf/CheckBox_Snippets/CSharp/Window1.xaml.cs#5)]
[!code-vb[CheckBox_Snippets#5](~/samples/snippets/visualbasic/VS_Snippets_Wpf/CheckBox_Snippets/VisualBasic/Window1.xaml.vb#5)]
]]></format>
</remarks>
<related type="ExternalDocumentation" href="https://go.microsoft.com/fwlink/?LinkID=160053">WPF Controls Gallery Sample</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public CheckBox ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.CheckBox.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; CheckBox();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.CheckBox" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="OnAccessKey">
<MemberSignature Language="C#" Value="protected override void OnAccessKey (System.Windows.Input.AccessKeyEventArgs e);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance void OnAccessKey(class System.Windows.Input.AccessKeyEventArgs e) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.CheckBox.OnAccessKey(System.Windows.Input.AccessKeyEventArgs)" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Sub OnAccessKey (e As AccessKeyEventArgs)" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; override void OnAccessKey(System::Windows::Input::AccessKeyEventArgs ^ e);" />
<MemberSignature Language="F#" Value="override this.OnAccessKey : System.Windows.Input.AccessKeyEventArgs -&gt; unit" Usage="checkBox.OnAccessKey e" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="e" Type="System.Windows.Input.AccessKeyEventArgs" />
</Parameters>
<Docs>
<param name="e">The <see cref="T:System.Windows.Input.AccessKeyEventArgs" /> that contains the event data.</param>
<summary>Called when the access key for a <see cref="T:System.Windows.Controls.CheckBox" /> is invoked.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="OnCreateAutomationPeer">
<MemberSignature Language="C#" Value="protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance class System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.CheckBox.OnCreateAutomationPeer" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Function OnCreateAutomationPeer () As AutomationPeer" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; override System::Windows::Automation::Peers::AutomationPeer ^ OnCreateAutomationPeer();" />
<MemberSignature Language="F#" Value="override this.OnCreateAutomationPeer : unit -&gt; System.Windows.Automation.Peers.AutomationPeer" Usage="checkBox.OnCreateAutomationPeer " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Windows.Automation.Peers.AutomationPeer</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Creates an <see cref="T:System.Windows.Automation.Peers.AutomationPeer" /> for the <see cref="T:System.Windows.Controls.CheckBox" />.</summary>
<returns>An <see cref="T:System.Windows.Automation.Peers.AutomationPeer" /> for the <see cref="T:System.Windows.Controls.CheckBox" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="OnKeyDown">
<MemberSignature Language="C#" Value="protected override void OnKeyDown (System.Windows.Input.KeyEventArgs e);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance void OnKeyDown(class System.Windows.Input.KeyEventArgs e) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Controls.CheckBox.OnKeyDown(System.Windows.Input.KeyEventArgs)" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Sub OnKeyDown (e As KeyEventArgs)" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; override void OnKeyDown(System::Windows::Input::KeyEventArgs ^ e);" />
<MemberSignature Language="F#" Value="override this.OnKeyDown : System.Windows.Input.KeyEventArgs -&gt; unit" Usage="checkBox.OnKeyDown e" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>PresentationFramework</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="e" Type="System.Windows.Input.KeyEventArgs" />
</Parameters>
<Docs>
<param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs" /> that contains the event data.</param>
<summary>Responds to a <see cref="T:System.Windows.Controls.CheckBox" /><see cref="E:System.Windows.UIElement.KeyDown" /> event.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This implementation marks the <xref:System.Windows.UIElement.KeyDown> event as handled by setting the <xref:System.Windows.RoutedEventArgs.Handled%2A> property of the event data to `true` when the user presses the plus or the minus key.
This method sets <xref:System.Windows.Controls.Primitives.ToggleButton.IsChecked%2A> to `true` when the user presses the plus key and to `false` when the user presses the minus key.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>If you override <see cref="M:System.Windows.Controls.CheckBox.OnKeyDown(System.Windows.Input.KeyEventArgs)" />, always call the base implementation in your <see cref="M:System.Windows.Controls.CheckBox.OnKeyDown(System.Windows.Input.KeyEventArgs)" /> implementation. Failure to call the base implementation prevents base classes from handling the event with a class handler, which might change the run-time behavior of the final class. You can call the base implementation either before or after your special handling, depending on your requirements.</para>
</block>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.