C# WPF为什么这个绑定不起作用?
试图绑定到的viewmodel中的属性:C# WPF为什么这个绑定不起作用?,c#,.net,wpf,data-binding,C#,.net,Wpf,Data Binding,试图绑定到的viewmodel中的属性: private TextActionValue _textActionVal; public TextActionValue TextActionVal { get { return _textActionVal; } set { _textActionVal = value; } } xaml: 文本属性已填充。当我一步一步的时候,里面
private TextActionValue _textActionVal;
public TextActionValue TextActionVal
{
get { return _textActionVal; }
set
{
_textActionVal = value;
}
}
xaml:
文本属性已填充。当我一步一步的时候,里面肯定有一个值
如果我只是绑定到一个基本的字符串属性,它就可以工作。它不喜欢“TextActionValue.Text”。这不是一个选项,除非我做一些重构,如果可以的话,我想避免重构
如果我在TextActionValue get中设置断点,则get永远不会被命中。这告诉我绑定永远不会被创建。为什么…或者我尝试做的是不可能的?尝试绑定到
TextActionVal.Text
而不是TextActionValue.Text
您正在尝试绑定到类而不是属性
调试时也要检查输出窗口以查看数据绑定错误。您的属性名为
TextActionVal
,但在您的TextBox的Text属性中,您将绑定设置为TextActionValue
为什么会有人否决这个问题?谁在乎这是不是一个简单的疏忽。你说的是两个角色的不同。因为只帮助一个人的问题是无用的。(学会…)这里50%的问题是“帮助一个人”…海报。@user1631520:你不能从描述性陈述中得出规范性陈述。阅读结束原因说明:这个问题不太可能对未来的访问者有所帮助
。这些是规则,其他一切都是无关的。上帝啊…谢谢你!!!我知道这将是一个愚蠢的错误。我会试着把答案记下来,如果是的话(我肯定是的),就是这样!答案有记号。谢谢。(我得等5分钟……但我接受)
<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>
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
}