C# wpfmvvm中的Int绑定
我正在用mvvm模式开发一个wpf应用程序。 我在ViewModel类中声明了一个Int属性。 当我更改此属性时,更改不会显示在UI中。 其他数据类型在我的应用程序中运行良好。 但是,如果将输入更改为对象,它将起作用C# wpfmvvm中的Int绑定,c#,wpf,mvvm,C#,Wpf,Mvvm,我正在用mvvm模式开发一个wpf应用程序。 我在ViewModel类中声明了一个Int属性。 当我更改此属性时,更改不会显示在UI中。 其他数据类型在我的应用程序中运行良好。 但是,如果将输入更改为对象,它将起作用 public class TestUserControlViewModel : UserControlViewModel { public TestUserControlViewModel( TestUserControlView testUserContr
public class TestUserControlViewModel : UserControlViewModel
{
public TestUserControlViewModel(
TestUserControlView testUserControlView)
{
UserControlView = testUserControlView;
Inital();
}
public RelayCommand AddPriceRelayCommand { get; set; }
public override void InitalCommand()
{
AddPriceRelayCommand = new RelayCommand(AddPrice);
}
private void AddPrice()
{
Price += 10;
}
public override void InitalVariable()
{
Price = 59;
}
private int _price;
public int Price
{
get { return _price; }
set
{
_price = value;
RaisePropertyChanged(() => Price);
}
}
}
XAML:
验证Datacontext是否如预期的那样,如何为XAML设置Datacontext?您是否在AddPrice中设置了断点以确认它实际上正在被调用?抓取Snoop并在运行时检查您的绑定。确保DataContext符合预期。您的代码似乎没有问题。
<TextBox Text="{Binding Path=Price, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" />