문제

서식을 제어하기 위해 창에 3 개의 종속성 속성을 등록하려고합니다. 나는 코드를 계속해서 보았지만 무언가를 놓치고 있어야합니다.

public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.White));
public Color TextColor {
    get { return (Color)base.GetValue(TextColorProperty); }
    set { base.SetValue(TextColorProperty, value); }
}

public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register("BackgroundColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.Black));
public Color BackgroundColor {
    get { return (Color)base.GetValue(BackgroundColorProperty); }
    set {
        base.SetValue(BackgroundColorProperty, value);
    }
}    
<TextBlock DockPanel.Dock="Top" Text="{Binding Name}" Foreground="{Binding TextColor,Converter={StaticResource DebugConverter}}" Background="{Binding Path=BackgroundColor}" />

Bea Stollnitz의 디버깅 방법을 사용하고 있지만 내 중단 점도 트리거되지 않습니다.

도움이 되었습니까?

해결책

이것은 DataContextTextBlock? 그것이 당신의 속성에 묶어야한다는 것을 어떻게 알 수 있습니까? Window?

어느 쪽이든 설정해야합니다 DataContext ~로 Window 인스턴스 또는 설정 Source (또는 RelativeSource, 또는 ElementName) 바인딩의 속성. 이러한 모든 속성은 Binding. DataContext 다른 사람 중 어느 것도 설정되지 않은 경우 폴백이지만, 당신이 그것을 설정하지 않았다고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top