Binding 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
바인딩 대상 및 데이터 원본의 속성을 연결하는 바인딩을 정의합니다.
UWP용 동등한 WinUI 2 API: Microsoft.UI.Xaml.Data.Binding(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조).
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Binding : BindingBase
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class Binding : BindingBase
Public Class Binding
Inherits BindingBase
<Binding .../>
- or -
<dependencyobject dependencyproperty="{Binding bindingArgs}" />
- 상속
- 특성
Windows 요구 사항
| 디바이스 패밀리 |
Windows 10 (10.0.10240.0에서 도입되었습니다.)
|
| API contract |
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)
|
예제
다음 코드 예제에서는 XAML에서 바인딩을 만드는 방법을 보여 줍니다. 전체 코드 목록은 XAML 데이터 바인딩 샘플을 참조하세요.
<StackPanel Margin="5">
<TextBlock Text="Name:" Style="{StaticResource DescriptionTextStyle}"
Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Text="{Binding Path=Name, Mode=TwoWay}"
Width="350" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBlock Text="Organization:" Style="{StaticResource DescriptionTextStyle}"
Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<!-- You can omit the 'Path=' portion of the binding expression. -->
<TextBox Text="{Binding Organization, Mode=TwoWay}" Width="350"
Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</StackPanel>
다음 예제 코드에서는 코드에서 바인딩을 만드는 방법을 보여 줍니다.
// Create the source string.
string s = "Hello";
// Create the binding description.
Binding b = new Binding();
b.Mode = BindingMode.OneTime;
b.Source = s;
// Attach the binding to the target.
TextBlock MyText = new TextBlock();
MyText.SetBinding(TextBlock.TextProperty, b);
// Create the source string.
String^ s = ref new String(L"Hello");
// Create the binding description.
Binding^ b = ref new Binding();
b->Mode = BindingMode::OneTime;
b->Source = s;
// Attach the binding to the target.
TextBlock^ MyText = ref new TextBlock();
MyText->SetBinding(MyText->TextProperty, b);
'Create the source string
Dim s As String = "Hello"
'Create the binding description
Dim b As New Binding()
b.Mode = BindingMode.OneTime
b.Source = s
'Attach the binding to the target
Dim MyText As New TextBlock()
MyText.SetBinding(TextBlock.TextProperty, b)
설명
{Binding} 태그 확장을 사용하면 바인딩 속성과 같은 설정을 포함하여 XAML에서 바인딩 값을 단일 특성 문자열로 Path Source지정할 수 있습니다. 데이터 바인딩 개념에 대한 자세한 내용은 데이터 바인딩을 자세히 참조하세요.
Binding 클래스는 {Binding} 태그 확장의 코드 숨김 노출로 간주될 수 있습니다. 바인딩이 대상에 이미 적용되어 있는 경우(XAML이 로드될 때 발생) 바인딩 개체의 읽기-쓰기 속성을 설정하여 런타임에 바인딩이 동작하는 방식을 변경할 수 없습니다. 모든 XAML 정의 바인딩은 변경할 수 없는 것으로 간주되어야 합니다. 그러나 새 Binding 개체를 만들고, 해당 속성을 설정하고, 특정 UI 요소 대상에서 새 바인딩을 설정할 수 있습니다 FrameworkElement.SetBinding. 자세한 내용은 코드에서 바인딩 만들기를 참조하세요.
Binding 개체는 데이터 개체에 FrameworkElement 대한 업데이트가 데이터 바인딩을 사용하는 속성에 자동으로 전파되도록 데이터 개체에 직접 종속성 속성을 연결합니다. Binding 클래스는 바인딩의 속성을 정의합니다. 각 바인딩에는 대상 요소, 대상 속성 및 데이터 원본이 있어야 하지만 일부 값은 기본적으로 지정하지 않으면 제공됩니다.
데이터 개체의 속성 또는 하위 속성에 바인딩하려면 Binding 개체의 속성을 설정합니다 Path . 코드 또는 XAML에서 설정하는 Path 방법에 대한 자세한 내용은 속성 경로 구문 또는 {Binding} 태그 확장을 참조하세요.
바인딩 클래스의 인스턴스를 여러 대상에 적용할 수 있습니다. 그러나 대상 요소에 연결한 후에는 Binding 개체의 속성 값을 수정할 수 없습니다.
참고
메서드를 FrameworkElement.SetBinding 호출하고 새 Binding 개체를 전달해도 기존 바인딩이 반드시 제거되는 것은 아닙니다. 대신 메서드를 DependencyObject.ClearValue 사용해야 합니다.
바인딩을 사용할 수 있거나 데이터 바인딩된 값으로 설정할 수 있는 속성에 대한 XAML 특성 사용에 대한 자세한 내용은 {Binding} 태그 확장을 참조하세요.
데이터 바인딩의 대상인 속성은 종속성 속성이어야 합니다. 자세한 내용은 종속성 속성 개요를 참조하세요.
생성자
| Binding() |
Binding 클래스의 새 인스턴스를 초기화합니다. |
속성
메서드
적용 대상
추가 정보
피드백
다음에 대한 사용자 의견 제출 및 보기