이것이 종속성 속성을 관리하는 방법에 대한 기본적인 오해라고 생각하지만 명확한 예를 찾을 수없는 것 같습니다. 내가 만약 내가 이해하지 못하는 어떤 예를 들어 다음 코드를 보면 DependencyProperty 값 및 변경된 콜백의 내부 관리
...public class MyControl
{
public static readonly DependencyProperty ExpressionProperty =
DependencyProperty.Register("Expression",
typeof (Expression),
typeof (MyControl),
new PropertyMetadata(ExpressionChanged));
public Expression Expression
{
get { return (Expression)GetValue(ExpressionProperty); }
set { SetValue(ExpressionProperty, value); }
}
private static void ExpressionChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
... Must respond to external change of property
... Update UI to reflect external change to property
}
private void RespondToInput()
{
... Do something to expression, add new elements or something
... Now expression has changed so I want to update the dependency property
... so datacontext gets new value.
SetValue(ExpressionProperty, updatedExpression);
}
}
, 나는이 RespondToInput 작업을 수행 할 때, 내가 지금하는 DependencyProperty를 업데이트 할 것입니다 만, PropertyChanged 콜백이 호출됩니다.이 시점에서 UI에서 변경 사항을 효과적으로 초기화했지만 원을 그리며 UI 업데이트를 시작합니다.
충분한 의미가 있는지 나는 모른다.
내가 뭘 잘못 했니 ??
감사합니다.
. DependencyProperty에 대한'ownerType' 인수를'ExpressionRichTextBox'에 등록하십시오. 속성은 클래스'MyControl'에 정의되어 있습니다. – Clemens
죄송합니다, 오타! 고마워! – Adam