我一直在使用MVVM我的WPF应用程序,现在一段时间的价值,但我试图保持禁用,直到一个按钮,就可以启用。没问题,我只是在ViewModel中做一个布尔,并将其绑定到该模型中。RaisePropertyChanged()不更新单个按钮
布尔:
private bool m_EnableLoadQuickStatsButton;
public bool EnableLoadQuickStatsButton
{
get { return m_EnableLoadQuickStatsButton; }
set { m_EnableLoadQuickStatsButton = value; RaisePropertyChanged("EnableLoadQuickStatsButton"); }
}
XAML按钮:
<Button Margin="5"
FontSize="14"
IsEnabled="{Binding EnableLoadQuickStatsButton}">
Load Quickstats
</Button>
的DataContext宣言:
DataContext="{StaticResource MainScreenViewModel}
.gif注意设计师和例如按钮的被使能/被初始属性值禁用:http://i.imgur.com/lpVeEBd.gif
该按钮是启用/禁用基于任何属性开始作为。但是,更改属性不会启用/禁用我的按钮。为什么是这样?我似乎没有任何其他控件和属性的问题。
编辑:
我的正常类实现INotifyPropertyChanged,有有在按预期工作我的WPF应用程序绑定到控制它们的值等性能。
EDIT2:应用程序的A.GIF,表示在数据绑定工作它的其他部分:http://i.imgur.com/lIvzHv7.gif
EDIT3:
System.Windows.Data Warning: 56 : Created BindingExpression (hash=51180192) for Binding (hash=56315736)
System.Windows.Data Warning: 58 : Path: 'EnableLoadQuickStatsButtonTest'
System.Windows.Data Warning: 60 : BindingExpression (hash=51180192): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=51180192): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=51180192): Attach to System.Windows.Controls.Button.IsEnabled (hash=23804398)
System.Windows.Data Warning: 67 : BindingExpression (hash=51180192): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=51180192): Found data context element: Button (hash=23804398) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=51180192): Activate with root item MainScreenViewModel (hash=64564967)
System.Windows.Data Warning: 108 : BindingExpression (hash=51180192): At level 0 - for MainScreenViewModel.EnableLoadQuickStatsButtonTest found accessor RuntimePropertyInfo(EnableLoadQuickStatsButtonTest)
System.Windows.Data Warning: 104 : BindingExpression (hash=51180192): Replace item at level 0 with MainScreenViewModel (hash=64564967), using accessor RuntimePropertyInfo(EnableLoadQuickStatsButtonTest)
System.Windows.Data Warning: 101 : BindingExpression (hash=51180192): GetValue at level 0 from MainScreenViewModel (hash=64564967) using RuntimePropertyInfo(EnableLoadQuickStatsButtonTest): 'False'
System.Windows.Data Warning: 80 : BindingExpression (hash=51180192): TransferValue - got raw value 'False'
System.Windows.Data Warning: 89 : BindingExpression (hash=51180192): TransferValue - using final value 'False'
Edit4:在启动调试输出创建一个新项目,它按预期工作,只是因为某些原因而不在我目前的项目上。
什么是你的'RaisePropertyChanged'吗?你的班级是否正确实施了'INotifyPropertyChanged'? – nvoigt
是的,所有其他属性和控件都能正常工作。除此之外,没有理由为什么。 –
是否正确设置了DataContext的视图属性? –