wpf数据双重绑定后,MVVM绑定控件失效
代码如下
UI是ListBox循环嵌套(此处只保留了核心控件)
<ListBox x:Name="lbOrder" ItemsSource="{Binding P_OrderList}" >
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelect, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Command="{Binding ElementName=lbOrder,Path=DataContext.DC_OrderSelected}" ToolTip="选择订单" />
<ListBox ItemsSource="{Binding OrderDetails}" >
<ListBox.ItemTemplate>
<DataTemplate >
<CheckBox IsChecked="{Binding IsSelectGoods, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Command="{Binding ElementName=lbOrder,Path=DataContext.DC_OrderDetailSelected}" ToolTip="选中订单商品" />
<TextBlock Text="{Binding InPrice}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
model的定义
public class P_OrderList{
public Guid Id { get; set; }
private bool _IsSelect;
public bool IsSelect
{
get { return _IsSelect; }
set { _IsSelect = value; OnPropertyChanged("IsSelect"); }
}
private ObservableCollection<OutOrderDetailDto> _OrderDetails;
public ObservableCollection<OutOrderDetailDto> OrderDetails
{
get { return _OrderDetails; }
set { _OrderDetails = value; OnPropertyChanged("OrderDetails"); }
}
}
public class OutOrderDetailDto
{
public Guid Id { get; set; }
public Guid OrderId { get; set; }
private decimal _InPrice;
public decimal InPrice
{
get { return _InPrice; }
set
{
_InPrice = value; OnPropertyChanged("InPrice");
}
}
private bool _IsSelectGoods;
public bool IsSelectGoods
{
get { return _IsSelectGoods; }
set { _IsSelectGoods = value; OnPropertyChanged("IsSelectGoods"); }
}
}
遇到的问题
1,选择了左侧商品或者订单的复选框。IsSelect 和IsSelectGoods的值已经发生了变化,但是CheckBox控件没有响应,IsChecked没有响应变化。
2,逻辑层,变更了 InPrice 的值,控件也没有变。
其他都绑定都没有问题,是不是双重绑定导致的?应该怎么解决该?