텍스트가 때때로 변경되는 텍스트 블록이있는 사용자 지정 사용자 정의 컨트롤이 있습니다.사용자 지정 Usercontrol TextBlock.text 바인딩
<TextBlock Text="{Binding ElementName=dashboardcounter, Path=Counter}" FontFamily="{Binding ElementName=dashboardcounter, Path=FontFamily}" HorizontalAlignment="Left" Margin="17,5,0,0" VerticalAlignment="Top" FontSize="32" Foreground="#FF5C636C"/>
.cs :
private static readonly DependencyProperty CounterProperty = DependencyProperty.Register("Counter", typeof(string), typeof(DashboardCounter));
public string Counter
{
get { return (string)GetValue(CounterProperty); }
set { SetValue(CounterProperty, value); }
}
나의 등급 :
private string _errorsCount;
public string ErrorsCount
{
get { return _errorsCount; }
set { _errorsCount = value; NotifyPropertyChanged("ErrorsCount"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
바인딩의 말 UserControl을 :
dashboardCounter.Counter = view.ErrorsCount;
01 TextBlocks 코드
XAML입니다
TextBlock은 절대적으로 아무것도 표시하지 않습니다.
무엇이 잘못 되었나요? 문자열이 동적이며 경우에 따라 변경됩니다. 그것은 원래 지능했지만, 난 대신 문자열 대신 당신은 당신의 종속성 속성의 세터를 호출하는 dashboardCounter.Counter = view.ErrorsCount;
를 사용하여 IValueConverter
그것이 ElementName에 값이 대소 문자를 구별하는 것이 될 수 있고 바인딩 : "ElementName = dashboardcounter"? – AirL
x : Name = "dashboardcounter"- 그게 아니라 – VisualBean
"counter"디렉토리를 설정하면 작동합니다. dashboardCounter.Counter = "sometext"; – VisualBean