반응형
읽기 전용 종속성 속성을 어떻게 생성합니까?
읽기 전용 종속성 속성을 어떻게 생성합니까? 그렇게하기위한 모범 사례는 무엇입니까?
특히 저를 가장 어렵게 만드는 것은 구현이 없다는 사실입니다.
DependencyObject.GetValue()
즉 소요 System.Windows.DependencyPropertyKey
파라미터로.
System.Windows.DependencyProperty.RegisterReadOnly
ependencyPropertyKey
대신 D 객체를 반환합니다 DependencyProperty
. 그렇다면 GetValue를 호출 할 수없는 경우 읽기 전용 종속성 속성에 어떻게 액세스해야합니까? 아니면 어떻게 든 DependencyPropertyKey
평범한 오래된 DependencyProperty
물건 으로 변환해야 합니까?
조언 및 / 또는 코드는 대단히 감사하겠습니다!
실제로 ( RegisterReadOnly 를 통해 ) 쉽습니다 .
public class OwnerClass : DependencyObject // or DependencyObject inheritor
{
private static readonly DependencyPropertyKey ReadOnlyPropPropertyKey
= DependencyProperty.RegisterReadOnly("ReadOnlyProp", typeof(int), typeof(OwnerClass),
new FrameworkPropertyMetadata(default(int),
FrameworkPropertyMetadataOptions.None));
public static readonly DependencyProperty ReadOnlyPropProperty
= ReadOnlyPropPropertyKey.DependencyProperty;
public int ReadOnlyProp
{
get { return (int)GetValue(ReadOnlyPropProperty); }
protected set { SetValue(ReadOnlyPropPropertyKey, value); }
}
//your other code here ...
}
개인 / 보호 / 내부 코드에서 값을 설정할 때만 키를 사용합니다. 보호 된 ReadOnlyProp
세터 로 인해 이것은 투명합니다.
참고 URL : https://stackoverflow.com/questions/1122595/how-do-you-create-a-read-only-dependency-property
반응형
'programing tip' 카테고리의 다른 글
이미지 UriSource 및 데이터 바인딩 (0) | 2020.11.27 |
---|---|
Eclipse 서버 시작 시간 초과를 어떻게 비활성화 할 수 있습니까? (0) | 2020.11.27 |
"For"루프 첫 번째 반복 (0) | 2020.11.27 |
PHP에서 정수 (intcmp)에 해당하는 strcmp (0) | 2020.11.27 |
mysql로드 데이터 infile이 파일 Errcode : 2의 상태를 가져올 수 없습니다. (0) | 2020.11.27 |