바인딩을 변경하고 바인딩을 변경하려는 UIElelement에 첨부 할 사용자 지정 연결된 속성을 작성할 수 있습니다. 이제해야 할 일은 바인딩이 변경되어야 할 때마다 연결된 속성에 대한 변경을 트리거하는 것입니다. 연결된 종속성 속성의 속성이 변경된 이벤트 표시 줄에서 UIElement에 액세스 할 수 있습니다.
<TextBlock local:Helper.DynamicBinding="{Binding SomeStatePropertyOfTheCurrentDataContext}" />
그리고 변경된 이벤트 핸들러 방법에
: 당신은이 같은 런타임에 바인딩을 변경의 필요성 건너 그러나 경우
private void OnDynamicBindingChanged(DependencyObject sender, PropertyChangedEventArgs args)
{
var senderButton = sender as TextBlock;
if((args.NewValue as string) == "MainText")
{
// bind to the property "MainText" of the current datacontext now
}
else if((args.NewValue as string) == "OtherText")
{
// bind to the property "OtherText" of the current datacontext now
}
}
, 기회는 당신의 전체 디자인을 향상시킬 수 있습니다!
감사합니다. 내 문제가 해결 될 것 같습니다. 사용자 정의 컨트롤의 바인딩 기능에 대한 자동화 테스트를 수행 중이므로 바인딩을 변경해야합니다. – Koynov