BindableObject 클래스

정의

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

public abstract class BindableObject : System.ComponentModel.INotifyPropertyChanged, Xamarin.Forms.Internals.IDynamicResourceHandler
type BindableObject = class
    interface INotifyPropertyChanged
    interface IDynamicResourceHandler
상속
BindableObject
파생
구현

설명

클래스는 BindableObject 애플리케이션 개발자가 변경 내용에 대한 응답으로 개체 간에 데이터를 동기화할 수 있도록 하는 데이터 스토리지 메커니즘을 제공합니다(예: MVVM 디자인 패턴의 보기 및 보기 모델 간). 네임스페이스의 모든 시각적 요소는 Xamarin.Forms 클래스에서 BindableObject 상속되므로 애플리케이션 개발자가 제공하는 보기 모델에 사용자 인터페이스 요소 뒤에 있는 데이터를 바인딩하는 데 모두 사용할 수 있습니다.

일반적으로 뷰의 속성 뒤에 있는 BindableObject데이터를 보기 모델의 속성에 바인딩하려면 애플리케이션 개발자가 다음을 수행해야 합니다.

먼저 개발자는 뷰에 속성 쌍을 만듭니다. 그 중 하나는 이 BindableProperty고, 다른 하나는 필요한 형식의 속성입니다. 아래 MockBindableObject 코드에서 은 일반적으로 프로덕션 코드의 사용자 인터페이스 개체가 되는 것을 의미합니다. 애플리케이션 개발자는 및 GetValue(BindableProperty) 를 사용하여 SetValue(BindableProperty, Object) 바인딩된 속성의 값을 가져와서 설정해야 합니다. 원하는 형식의 속성은 바인딩된 속성의 대상이 구현할 인터페이스를 제공합니다.

class MockBindableObject : BindableObject
{
    // App developers should use the method below in production code for 
    // better performance
    public static readonly BindableProperty BoundNameProperty =
         BindableProperty.Create ("Foo", typeof (string),
                                  typeof (MockBindableObject),
                                  default(string));

    // App developers should use the method below during development for
    // design-time error checking as the codebase evolves.
    // public static readonly BindableProperty FooProperty 
    //     = BindableProperty.Create<MockBindableObject, string> (
    //         o => o.Foo, default (string)
    //     );

    public string BoundName
    {
        get { return (string) GetValue (BoundNameProperty); }
        set { SetValue (BoundNameProperty, value); }
    }
}

둘째, 개발자는 인터페이스를 구현하는 클래스에서 바인딩된 속성에 대한 구현을 INotifyPropertyChanged 만듭니다. MVVM 디자인 패턴에서는 일반적으로 보기 모델에 의해 수행됩니다. 애플리케이션 개발자는 모델 보기로 사용하려는 클래스에서 인터페이스를 구현 INotifyPropertyChanged 해야 합니다. 아래 예제에서 앱 개발자는 속성이 Name 구현되는 idiomatic 방식을 적어 두어야 합니다. 먼저 속성이 실제로 변경되었는지 확인하고, 그렇지 않은 경우 를 반환한 다음, 값을 할당하고 메서드를 OnPropertyChanged(String) 호출해야 합니다. 또한 아래 예제의 속성은 Name 필드를 래핑하기 name 만 합니다. 실제로 애플리케이션 개발자는 애플리케이션 데이터를 저장할 다른 모델을 선택할 수 있습니다.

class MockViewModel : INotifyPropertyChanged
{
    string name;

    public string Name
    {
        get { return name; }
        set
        {
            // OnPropertyChanged should not be called if the property value
            // does not change.
            if (name == value)
                return;
            name = value;
            OnPropertyChanged ();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    void OnPropertyChanged (string propertyName = null)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler (this, new PropertyChangedEventArgs (propertyName));
    }
}

셋째, 마지막으로 애플리케이션 개발자는 BindableObject의 instance INotifyPropertyChanged를 구현하는 instance 바인딩합니다. MVVM 디자인 패턴의 어휘에서 이것은 "보기의 instance 보기 모델의 instance 바인딩"입니다. 이 단계가 완료되면 바인딩 단계 중에 전달된 열거형 값 BindingMode (있는 경우)에 따라 결정되는 방식으로 뷰 모델과 뷰 모델 간에 데이터 변경 내용이 전파됩니다.

위의 클래스를 참조하는 프로젝트에 포함된 아래 코드는 및 MockViewModelMockBindable instance 만들고, 일부 초기화를 수행하고, 바인딩을 설정한 다음, 단방향 바인딩을 보여 줍니다. 아래 코드는 예외를 throw하지 않고 실행됩니다.

public static void OneWayDemo ()
{
    var view = new MockBindableObject ();
    var viewModel = new MockViewModel ();

    // Pre-load the ViewModel, for demonstration purposes
    viewModel.Name = "Testing";

    // Create a one-way (default) binding
    view.SetBinding (MockBindableObject.BoundNameProperty, new Binding ("Name"));

    // App developers should only set the binding context after all
    // calls to SetBinding() have been made, for performance reasons.
    view.BindingContext = viewModel;

    // In a one way binding, the ViewModel value will be used to update
    // the values in the View during initialization
    if (view.BoundName != "Testing")
        throw new Exception ();

    view.BoundName = "gnitseT";

    // in a one way binding, changes to the View will NOT update the ViewModel
    if (viewModel.Name == "gnitseT")
        throw new Exception ();
}

생성자

BindableObject()

BindableObject 클래스의 새 인스턴스를 초기화합니다.

필드

BindingContextProperty

해당 인터페이스가 BindingContext 속성에서 제공된 바인딩된 속성을 구현합니다.

속성

BindingContext

BindableObject에 속하는 바인딩된 속성에 의해 대상으로 지정될 속성을 포함하는 개체를 가져오거나 설정합니다.

Dispatcher

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

메서드

ApplyBindings()

바인딩을 BindingContext에 적용합니다.

ClearValue(BindableProperty)

property에 대해 SetValue로 설정된 모든 값을 지웁니다.

ClearValue(BindablePropertyKey)

propertyKey로 식별되는 속성에 대해 SetValue로 설정된 모든 값을 지웁니다.

CoerceValue(BindableProperty)

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

CoerceValue(BindablePropertyKey)

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

GetValue(BindableProperty)

BindableProperty에 포함되는 값을 반환합니다.

GetValues(BindableProperty, BindableProperty)
사용되지 않습니다.

Xamarin.Forms 플랫폼에서 내부용으로 사용합니다.

GetValues(BindableProperty, BindableProperty, BindableProperty)
사용되지 않습니다.

Xamarin.Forms 플랫폼에서 내부용으로 사용합니다.

IsSet(BindableProperty)

대상 속성이 있고 설정된 경우 true를 반환합니다.

OnBindingContextChanged()

BindingContext가 변경될 때 작업을 실행하려면 이 메서드를 재정의합니다.

OnPropertyChanged(String)

자식 클래스에서 이 메서드를 호출하여 속성이 변경되었음을 알립니다.

OnPropertyChanging(String)

자식 클래스에서 이 메서드를 호출하여 속성이 변경되었음을 알립니다.

RemoveBinding(BindableProperty)

이전 바인딩 설정을 제거합니다.

SetBinding(BindableProperty, BindingBase)

속성에 바인딩을 할당합니다.

SetInheritedBindingContext(BindableObject, Object)

중첩된 요소에 상속된 컨텍스트를 설정합니다.

SetValue(BindableProperty, Object)

지정한 속성의 값을 설정합니다.

SetValue(BindablePropertyKey, Object)

propertyKey의 값을 설정합니다.

SetValueCore(BindableProperty, Object, SetValueFlags)

Xamarin.Forms 플랫폼에서 내부용으로 사용합니다.

UnapplyBindings()

이전 모든 바인딩 설정을 적용 해제합니다.

이벤트

BindingContextChanged

BindingContext 속성이 변경될 때마다 발생됩니다.

PropertyChanged

속성이 변경된 경우 발생됩니다.

PropertyChanging

속성이 변경되려고 할 때 발생됩니다.

명시적 인터페이스 구현

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

Xamarin.Forms 플랫폼에서 내부용으로 사용합니다.

확장 메서드

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

속성에 바인딩을 만들고 적용합니다.

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)
사용되지 않습니다.

식에서 바인딩을 만들고 적용합니다.

SetOnAppTheme<T>(BindableObject, BindableProperty, T, T)

애플리케이션 개발자가 유효성 검사, 형식 강제 변환 및 이벤트 시스템을 활성화하여 한 개체에서 다른 개체로 데이터에 대한 변경 내용을 전파할 수 있는 메커니즘을 제공합니다. BindableProperty.

적용 대상