종속성 속성에서 세터가 실행되지 않습니까?
몇 가지 의심을 해소하기 위해 간단한 질문을 하겠습니다.요소가 종속 속성에 바인딩되어 있는 경우 세터는 실행되지 않습니까?
public string TextContent
{
get { return (string)GetValue(TextContentProperty); }
set { SetValue(TextContentProperty, value); Debug.WriteLine("Setting value of TextContent: " + value); }
}
public static readonly DependencyProperty TextContentProperty =
DependencyProperty.Register("TextContent", typeof(string), typeof(MarkdownEditor), new UIPropertyMetadata(""));
...
<TextBox Text="{Binding TextContent}" />
제 세터에서 아래가 실행되지 않는 것을 알 수 있었습니다.
Debug.WriteLine("Setting value of TextContent: " + value);
WPF 바인딩 엔진 호출GetValue
그리고.SetValue
직접(프로퍼티 설정자 및 게터 포함)XAML 마크업(및 올바르게 컴파일)으로 서포트할 수 있도록 속성이 필요합니다.
DependencyProperty를 작성하려면 DepdencyProperty 유형의 정적 필드를 유형에 추가하고 DependencyProperty를 호출합니다.Register()를 사용하여 종속성 속성의 인스턴스를 만듭니다.DependyProperty의 이름은 항상 다음과 같이 끝나야 합니다.소유물.이것은 WPF에서의 명명 규칙입니다.
통상의 방법으로 액세스 할 수 있도록 하기 위해서.속성 래퍼를 추가해야 하는 NET 속성입니다.이 래퍼는 DependencyObject에서 상속된 GetValue() 및 SetValue() 메서드를 사용하여 DependencyProperty를 키로 전달함으로써 내부적으로 값을 가져오고 설정하는 것 외에 다른 작업을 하지 않습니다.
이러한 속성은 코드에서 속성을 설정할 때만 호출되므로 이러한 속성에 논리를 추가하지 마십시오.XAML에서 속성을 설정하면 SetValue() 메서드가 직접 호출됩니다.
각 Dependency Property는 변경 알림, 값 강제 및 검증을 위한 콜백을 제공합니다.이러한 콜백은 의존속성에 등록됩니다.
출처 : http://www.wpftutorial.net/DependencyProperties.html
언급URL : https://stackoverflow.com/questions/4225373/setters-not-run-on-dependency-properties
'programing' 카테고리의 다른 글
git에서 여러 원격 분기 삭제 (0) | 2023.04.22 |
---|---|
Python Setup 비활성화 경로 길이 제한 장단점? (0) | 2023.04.22 |
XAML만 사용하고 코드 배후는 사용하지 않고 ListBox를 정렬하려면 어떻게 해야 합니까? (0) | 2023.04.17 |
Git 브랜치에서 다른 브랜치로 단일 파일 버전을 복사하려면 어떻게 해야 합니까? (0) | 2023.04.17 |
Swift-Language 오류 처리 (0) | 2023.04.17 |