ToggleButton.IsChecked 屬性

定義

取得或設定是否已核取 ToggleButtonGets or sets whether the ToggleButton is checked.

public:
 property Nullable<bool> IsChecked { Nullable<bool> get(); void set(Nullable<bool> value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.NullableBoolConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public bool? IsChecked { get; set; }
member this.IsChecked : Nullable<bool> with get, set
Public Property IsChecked As Nullable(Of Boolean)

屬性值

如果已核取 true 則為 ToggleButton,如果未核取 ToggleButton 則為 false,否則為 nulltrue if the ToggleButton is checked; false if the ToggleButton is unchecked; otherwise null. 預設為 falseThe default is false.

屬性

範例

下列範例會建立設定為不定狀態的 CheckBoxThe following example creates a CheckBox set to an indeterminate state.

<CheckBox Name="checkBox1" IsThreeState="True" 
          IsChecked="{x:Null}">
  A CheckBox in an indeterminate state
</CheckBox>

備註

繼承自 ToggleButton 的控制項會決定 null此屬性時的行為。A control that inherits from ToggleButton determines its behavior when this property is null.

核取方塊CheckBox

當 [IsThreeState] 屬性設定為 [true] 時,使用者可以按一下 CheckBox 以挑選三個可能的狀態。When the IsThreeState property is set to true, a user can click a CheckBox to pick three possible states. 下表描述 CheckBox的三種狀態。The following table describes the three states of a CheckBox.

CheckBox 的狀態State of the CheckBox IsChecked 的值Value of IsChecked
已檢查Checked true
未核取Unchecked false
處於Indeterminate null

如果 IsThreeState 為 false,您仍然可以透過程式設計方式將此屬性設定為 nullCheckBox 處於不定狀態,但是使用者無法透過 使用者介面 (UI)user interface (UI)CheckBox 設定為未定狀態。If IsThreeState is false, you can still programmatically set this property to null to put the CheckBox in an indeterminate state, but the user cannot set the CheckBox to the indeterminate state through the 使用者介面 (UI)user interface (UI).

RadioButtonRadioButton

如果您將此屬性設定為 RadioButton上的 null,則會取消核取該 RadioButtonIf you set this property to null on a RadioButton, the RadioButton is unchecked.

XAML Attribute UsageXAML Attribute Usage

<物件IsChecked= "Boolean"/><object IsChecked="Boolean"/>

-或--or-

<物件IsChecked= "{x:Null 標記延伸模組}"/><object IsChecked="{x:Null Markup Extension}"/>

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field IsCheckedProperty
設定為 true 的中繼資料屬性Metadata properties set to true BindsTwoWayByDefault

適用於