확인 - 두 가지 추가 속성 (영문 텍스트, 불어 텍스트)이 포함 된 사용자 지정 레이블을 만들어 두 번째로 단순한 시나리오라고 생각했습니다. 현재는이 같은 구조 :WPF 사용자 지정 컨트롤 및 DependencyProperty를 통한 속성 표시
Public Class myCustomLabel
Inherits System.Windows.Controls.Label
Public myEnglishTextProperty As DependencyProperty = DependencyProperty.Register("myEnglishText", GetType(String), GetType(myCustomLabel), New PropertyMetadata("English", New PropertyChangedCallback(AddressOf TextChanged)))
Public myFrenchTextProperty As DependencyProperty = DependencyProperty.Register("myFrenchText", GetType(String), GetType(myCustomLabel), New PropertyMetadata("Francais", New PropertyChangedCallback(AddressOf TextChanged)))
Public Sub New()
'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
'This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(GetType(myCustomLabel), New FrameworkPropertyMetadata(GetType(myCustomLabel)))
End Sub
Public Property myEnglishText() As String
Get
Return MyBase.GetValue(myFrenchTextProperty)
End Get
Set(ByVal value As String)
MyBase.SetValue(myFrenchTextProperty, value)
End Set
End Property
Public Property myFrenchText() As String
Get
Return MyBase.GetValue(myFrenchTextProperty)
End Get
Set(ByVal value As String)
MyBase.SetValue(myFrenchTextProperty, value)
End Set
End Property
Private Sub TextChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
If DesignerProperties.GetIsInDesignMode(Me) = True Then
Me.Content = myEnglishText
Else
If myUser.Language = "E" Then
Me.Content = myEnglishText
Else
Me.Content = myFrenchText
End If
End If
End Sub
End Class
내 검사 창 그리드 XAML은 간단하다 : 이것은 개발 환경에서 작동하는 것 같다
<Grid>
<my:myCustomLabel myEnglishText="English Text" myFrenchText="English Text" Height="25" Width="100" Background="Aqua" Foreground="Black"/>
</Grid>
- 영어와 프랑스어 텍스트를 변경 변경 설계 미리보기에서와 앱이 실행되고 테스트 창이 열릴 때 작동합니다. 그러나 첫 번째 시간 - 나는 검사 창에게 나는 다음과 같은 메시지가 두 번째 열 경우 :
'myEnglishText'속성이 이미 'myCustomLabel'에 의해 등록되었다.
종속성 속성 선언을 공유로 변경하면이 문제는 해결됩니다. 콘텐츠 (클래스로 인스턴스화해야 함)를 업데이트하십시오. 영어와 프랑스어 레이블이 변경되면 디자인 타임에 콘텐츠 속성을 업데이트하면됩니다.
이 방법이 있습니까? 또는 내가 필요로하는 것에 대한 의존성 속성 과잉이 있습니까?
감사합니다.의존성 객체 "d"는 내내 얼굴을 쳐다보고 있었고 결코 2와 2를 함께 사용하지 않았습니다. – Gatmando