Mvvm BindableBase:绑定到嵌套属性不调用setter
我有以下型号:Mvvm BindableBase:绑定到嵌套属性不调用setter,mvvm,binding,windows-runtime,winrt-xaml,Mvvm,Binding,Windows Runtime,Winrt Xaml,我有以下型号: public class Car : BindableBase { private string _model; private string _wheels; public string Model { get { return _model; } set { SetProperty(ref _model, value); } } public string Wheels {
public class Car : BindableBase
{
private string _model;
private string _wheels;
public string Model
{
get { return _model; }
set { SetProperty(ref _model, value); }
}
public string Wheels
{
get { return _wheels; }
set { SetProperty(ref _wheels, value); }
}
}
public class Customer : BindableBase
{
private Car _car;
public Car Car
{
get { return _car; }
set { SetProperty(ref _car, value); }
}
}
绑定方式如下所示:
<Page.Resources>
<viewModels:CustomerViewModelLocator x:Key="PageViewModel" />
</Page.Resources>
<StackPanel>
<TextBox Background="AliceBlue" Text="{Binding ViewModel.Car.Model, Mode=TwoWay, Source={StaticResource PageViewModel}}"></TextBox>
<TextBox Background="AliceBlue" Text="{Binding ViewModel.Car.Wheels, Mode=TwoWay, Source={StaticResource PageViewModel}}"></TextBox>
</StackPanel>
我在设计时视图中使用ViewModelLocator模式,它看起来不错。但在运行时,我不会触及模型的设定者
我做错了什么
客户模型中的琐碎类型将被设置…如果Car为null,则会发生这种情况。尝试在Customer中设置_car=new car()。有时。。。我想?($§?=($§(?')($=§!/&/)=“§&&$/&%/()&§”($/=?&=)谢谢!