2015-10-18 73 views
-2

我想在文本框中顯示字符串_lunedi,使用InitializeBoxes()定期更新字符串_lunedi。文本塊綁定文本

我有我的課:

public event PropertyChangedEventHandler PropertyChanged; 
private string _lunedi= "lunedi "; 
    public string lunedi 
    { 
     get { return this._lunedi; } 

     set 
     { 
      if (value != this._lunedi) 
      { 
       this._lunedi = value; 
       NotifyPropertyChanged("lunedi"); 
      } 
     } 
    } 


    public void NotifyPropertyChanged(string propertyName) 
    { 
     if (this.PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 

白衣這種方法改變lunedi:

private void InitializeBoxes() 
    { 
     lunedi += todayPivot.Day; 
    } 

XAML:

<Border> 
    <TextBlock Text="{Binding Path=lunedi, UpdateSourceTrigger=PropertyChanged}"></TextBlock> 
</Border> 

的問題是,該文本塊的文本爲空。 謝謝。

+2

的可能的複製[如何簡單的字符串值到一個文本框綁定?](http://stackoverflow.com/questions/17764323/how-to-bind-a-simple-string-value-to-a-text-box) –

+0

你如何綁定視圖模型來查看? –

+0

你發佈的代碼看起來很好。如果你在該屬性的「setter」中放置一個斷點,它會被擊中嗎? –

回答

0

聽起來就像是綁定使用一次嘗試這個代替

<Border> 
<TextBlock Text="{Binding Path=lunedi, Mode=OneWay}"></TextBlock> 

+0

這是什麼? – TreeTree

+0

抱歉,您應該現在就看到它 –