【发布时间】:2015-06-17 09:12:36
【问题描述】:
在我的 WPF 应用程序中,我有一些属性已绑定到 XAML 对应项,但由于某种原因,当它们的值发生更改时不会设置它们。我已经实现了INotifyPropertyChanged 接口并为此视图设置了我的DataContext,但它仍然没有进行任何更改。
对于这个 ViewModel 中的其他属性,我有同样的模式,它们确实有效,而其他属性则没有。
这是我当前代码的 sn-p:
视图模型
public class TestViewModel : INotifyPropertyChanged
{
private string testString;
public TestViewModel()
{
.....
this.RunCommand = new RelayCommand(this.RunAction);
}
public string TestString
{
get
{
return this.testString;
}
set
{
this.testString = value;
this.OnPropertyChanged("TestString");
}
}
private void RunAction()
{
.....
this.testString = "Running.";
}
}
查看
<StatusBarItem>
<TextBlock Text="{Binding Path=TestString, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" />
</StatusBarItem>
DataContext(在另一个 MainWindow 类的代码隐藏中设置)
var testViewModel = SimpleIoc.Default.GetInstance<TestViewModel>();
var testWindow = new TestWindow() { DataContext = testViewModel };
testingWindow.Show();
如果有帮助,这是使用 MVVM-Light 在类之间传递属性的多窗口应用程序的一部分。
【问题讨论】:
-
什么是
ProcessIndicator? -
对不起。编辑为
TestString。
标签: c# wpf xaml mvvm inotifypropertychanged