[英]DataGrid CheckboxColumn bound to VM property not calling setter
ETA: I'm using Caliburn.Micro so the x:Name property for the Grid is being bound to a Property on the VM called MyData which in turn has the property IsTrue. 预计到达时间:我使用的是Caliburn.Micro,因此网格的x:Name属性被绑定到VM上名为MyData的属性,该属性又具有IsTrue属性。 MyData does inherit from PropertyChangeBase MyData确实继承自PropertyChangeBase
I have a DataGrid with the a column bound to a bool property on the ViewModel: 我有一个DataGrid,其中的列绑定到ViewModel的bool属性:
<DataGrid x:Name="MyData"
AutoGenerateColumns="False"
Width="282"
RowHeaderWidth="0"
CanUserAddRows="false">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="MyChckColumn"
Binding="{Binding IsTrue, Mode=TwoWay}"
Width="80"/>
</DataGrid.Columns>
</DataGrid>
it only goes into the setter when something else on the grid is selected, but not when I actually check a box that was empty. 仅当选择了网格上的其他内容时,它才会进入设置器,而当我实际选中一个为空的框时,它才进入设置器。
public bool IsTrue
{
get
{
return _isTrue;
}
set
{
if (value.Equals(_isTrue)) return;
_isTrue= value;
NotifyOfPropertyChange(() => IsTrue);
}
}
Is there some validation method I need to call, or a trigger that needs to be set? 我需要调用某些验证方法,还是需要设置触发器?
To get the behavior you are after, you would have to set the UpdateSourceTrigger
property of the binding to PropertyChanged
. 要获得您想要的行为,必须将绑定的UpdateSourceTrigger
属性设置为PropertyChanged
。
By default the binding source is updated when the cell looses focus. 默认情况下,单元格失去焦点时,绑定源将更新。
Binding="{Binding IsTrue, UpdateSourceTrigger=PropertyChanged}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.