この記事は機械翻訳されています。英語版の記事を表示するには、[英語] のチェック ボックスをオンにしてください。また、テキストにマウス ポインターを合わせると、ポップアップ ウィンドウに英語のテキストを表示することもできます。
翻訳
英語

FrameworkElement.DataContext プロパティ

 

公開日: 2016年10月

要素がデータ バインディングに含まれている場合に、その要素のデータ コンテキストを取得または設定します。

名前空間:   System.Windows
アセンブリ:  PresentationFramework (PresentationFramework.dll 内)

[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]
public object DataContext { get; set; }

プロパティ値

Type: System.Object

データ コンテキストとして使用するオブジェクト。

Data context is a concept that allows elements to inherit information from their parent elements about the data source that is used for binding, as well as other characteristics of the binding, such as the path.

Data context can be set directly to a TLA#tla_clr object, with the bindings evaluating to properties of that object. Alternatively, you can set the data context to a T:System.Windows.Data.DataSourceProvider object.

This dependency property inherits property values. If there are child elements without other values for P:System.Windows.FrameworkElement.DataContext established through local values or styles, then the property system will set the value to be the P:System.Windows.FrameworkElement.DataContext value of the nearest parent element with this value assigned.

Alternatively, you can use one of the following properties of the T:System.Windows.Data.Binding class to specify the binding source explicitly: P:System.Windows.Data.Binding.ElementName, P:System.Windows.Data.Binding.Source, or P:System.Windows.Data.Binding.RelativeSource. For more information, see How to: Specify the Binding Source.

In TLA2#tla_xaml, P:System.Windows.FrameworkElement.DataContext is most typically set to as a T:System.Windows.Data.Binding declaration. You can use either property element syntax or attribute syntax. Attribute syntax is shown in the example on this page. You can also use code to set P:System.Windows.FrameworkElement.DataContext.

DataContext is a bindable property, to facilitate scenarios where one context might be bound to another. However, if you bind to DataContext, be careful to not create circular binding references (do not bind a DataContext to itself, which is possible to do because of the property value inheritance nature of the DataContext property).

<object>
  <object.DataContext>
    <dataContextObject />
  </object.DataContext>
</object>

<object DataContext="bindingUsage"/>
- or -
<object DataContext="{resourceExtension contextResourceKey}"/>

dataContextObject

A directly embedded object that serves as data context for any bindings within the parent element. Typically, this object is a T:System.Windows.Data.Binding or another T:System.Windows.Data.BindingBase derived class. Alternatively, raw data of any TLA2#tla_clr object type intended for binding may be placed here, with the actual bindings defined later.

bindingUsage

A binding usage that evaluates to an appropriate data context. For details, see Binding Markup Extension.

resourceExtension

One of the following: or . This usage is used when referring to raw data defined as an object in resources. See XAML Resources.

contextResourceKey

The key identifier for the object being requested from within a T:System.Windows.ResourceDictionary.

Identifier field

DataContextProperty

Metadata properties set to true

Inherits

The following example illustrates how a data context acts on a binding and provides the information that defines the specific values of bound properties.

<Window.Resources>
  <src:LeagueList x:Key="MyList" />
</Window.Resources>
<DockPanel DataContext="{Binding Source={StaticResource MyList}}">

.NET Framework
3.0 以降で使用可能
Silverlight
2.0 以降で使用可能
Windows Phone Silverlight
7.0 以降で使用可能
トップに戻る
表示: