2016-12-23 4 views
0

매우 이상한 문제가 있습니다. 바인딩을 설정하고 바인딩을 다른 속성으로 변경하면 작동하지 않습니다. 이 간단한 예제 FinalTotal 변경UWP : 데이터 바인딩 바꾸기

lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("Subtotal"), Source = Order, Mode = BindingMode.OneWay }); 
lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("FinalTotal"), Source = Order, Mode = BindingMode.OneWay }); 

에서

봐는 lblTotal 텍스트는 는 변경되지 않습니다.

이제 첫 줄을 주석 처리했습니다.

//lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("Subtotal"), Source = Order, Mode = BindingMode.OneWay }); 
lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("FinalTotal"), Source = Order, Mode = BindingMode.OneWay }); 

지금 작업 중 !!!! FinalTotal을 변경하면 lblTotal 텍스트가 변경됩니다! 왜 그런가?

또한 BindingOperations.ClearBinding()은 UWP에서 사용할 수 없습니다. 그래서 빈 바인딩으로 대체하려고했지만 여전히 작동하지 않습니다.

lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("Subtotal"), Source = Order, Mode = BindingMode.OneWay }); 

//remove binding - not sure if this is correct way to remove binding because 
//BindingOperations.ClearBinding() isn't available in UWP! 
BindingOperations.SetBinding(lblTotal, TextBlock.TextProperty, new Binding()); 

lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("FinalTotal"), Source = Order, Mode = BindingMode.OneWay }); 

내 질문은 : 1. 어떻게 UWP 바인딩 교체? 2. UWP에서 기존 바인딩을 제거하는 방법 (즉, BindingOperations.ClearBinding())과 동일한 기능을 제거 하시겠습니까? 어떤 도움

덕분에 ...

+0

단지 quess - BindingMode를 TwoWay로 변경할 수 있습니까? – Sasha

+0

안녕 사샤, 나는 그것을 시도했지만 여전히 작동하지 않습니다 : ( – Sam

+0

"소계"에 대한 바인딩 설정 오류가 발생합니다. 출력 창에 바인딩 오류가 표시됩니까? – Sasha

답변

3

FrameworkElement.SetBinding method에 선언으로 :

SetBinding 메서드를 호출하고 반드시 제거되지 않습니다 새로운 Binding 객체 전달 기존 바인딩. 대신, 먼저 DependencyObject.ClearValue 메서드를 호출 한 다음 SetBinding을 호출해야합니다.

그래서 당신은 다음과 같이 코드를 변경할 수 있습니다

lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("Subtotal"), Source = Order, Mode = BindingMode.OneWay }); 
lblTotal.ClearValue(TextBlock.TextProperty); 
lblTotal.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("FinalTotal"), Source = Order, Mode = BindingMode.OneWay }); 

를이 코드 후 작동 할 수 있어야한다. 자세한 내용은 비고, FrameworkElement.SetBindingBindingOperations.SetBinding을 참조하십시오.

+0

Jay에게 감사하지만이 코드는 테스트하지 않았지만 좋아 보인다. 내가 일하러 돌아 왔을 때 문제가 있으면 다시 해보겠습니다! – Sam

+0

제이, 작동했습니다! 늦게 답장을 보내서 죄송합니다! ks! – Sam

관련 문제