2012-09-24 39 views
-1

物業在我的viewmodel中,我試圖綁定到:WPF爲什麼這個綁定不起作用?

private TextActionValue _textActionVal; 
    public TextActionValue TextActionVal 
    { 
     get { return _textActionVal; } 
     set 
     { 
      _textActionVal = value; 
     } 
    } 

XAML:

<Grid Margin="0,15,15,15" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <GroupBox Grid.Row="1" BorderThickness="0"> 
     <TextBox Margin="0,5,0,5" AcceptsReturn="True" AcceptsTab="True" Text="{Binding TextActionValue.Text}" HorizontalAlignment="Stretch" MinHeight="100"></TextBox> 
    </GroupBox> 
</Grid> 

最後的TextActionValue類:

public class TextActionValue : ISomeAction, INotifyPropertyChanged 
{ 
    private String _text; 
    public String Text 
    { 
     get { return _text; } 
     set 
     { 
      _text = value; 
      OnPropertyChanged("Text"); 
     } 
    } 

    #region INotifyPropertyChanged Members 

    public event PropertyChangedEventHandler PropertyChanged; 
    public void OnPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
    #endregion 
} 

text屬性被填充。當我踏入它時,那裏肯定有價值。

如果我只是綁定到一個基本的字符串屬性它的作品。它不喜歡「TextActionValue.Text」。除非我做一些我想避免的重構,否則這不是一種選擇。

如果我在TextActionValue中放置了一個斷點get ... get不會被命中。所以這是告訴我綁定從來沒有創建。爲什麼雖然...或者是我試圖做不到的事情?

+1

您的財產被稱爲'TextActionVal',但在您的TextBox的文本屬性中,您正在設置綁定到'TextActionValue' – Dante

+2

爲什麼世界上有人會投這個問題?誰在乎這是否是一個簡單的疏忽。你說的是兩個角色的差異。 – tronious

+0

因爲只有幫助一個人的問題毫無用處。 (學習[調試數據綁定](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application.aspx )...) –

回答

2

嘗試的TextActionValue.Text

您試圖綁定到類而不是屬性綁定到TextActionVal.Text代替。

同時在調試時檢查您的輸出窗口以查看數據綁定錯誤。

+0

好主...謝謝你!我知道這將是一個愚蠢的愚蠢的錯誤。如果是這樣,我會嘗試標記爲答案(我確定它是) – tronious

+0

就是這樣!答案標出。欣賞它。 (我必須等5分鐘......但我會接受) – tronious