2012-09-24 38 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