【发布时间】:2012-09-24 15:33:45
【问题描述】:
我试图绑定到的视图模型中的属性:
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
}
文本属性已填充。当我踩到它时,肯定有一个价值。
如果我只是绑定到一个基本的字符串属性,它就可以工作。它不喜欢“TextActionValue.Text”。这不是一个选择,除非我做一些我想尽可能避免的重构。
如果我在 TextActionValue get 中放置一个断点...get 永远不会被命中。所以这告诉我绑定永远不会创建。为什么...或者我试图做的事情是不可能的?
【问题讨论】:
-
您的属性名为
TextActionVal,但在您的 TextBox 的 Text 属性中,您将绑定设置为TextActionValue -
为什么会有人反对这个问题?谁在乎这是否是一个简单的疏忽。你说的是两个字符的区别。
-
因为只帮助一个人的问题是没有用的。 (学习debug data bindings...)
-
这里 50% 的问题是为了“帮助一个人”……发帖者。
-
@user1631520:您不能从描述性陈述中推导出规范性陈述。阅读原因描述:
This question is unlikely to help any future visitors。这些是规则,其他的都无关紧要。
标签: c# .net wpf data-binding