我有一个包含Checkbox的DatagridTemplate列,当ItemSource上的属性为“J”时,通过转换器进行检查,当属性为“N”时取消选中。
这样可行,但是现在我希望将属性设置为“J”,如果我选中复选框或“N”则取消选中它。
我的专栏:
<local:JNConverter x:Key="JNConverter" />
<DataGridTemplateColumn Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Center">
<CheckBox Name="auto" HorizontalAlignment="center" IsChecked="{Binding Path=Autonummering, Converter={StaticResource JNConverter}, Mode=TwoWay}" />
</ContentControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我的转换器:
Public Class JNConverter 实现IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
If value IsNot Nothing AndAlso value.ToString.ToLower = "j" Then
Return True
Else
Return False
End If
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
If CType(value, Boolean) Then
Return "J"
Else
Return "N"
End If
End Function
结束班
My Itemsource是一个List(Of Attribuut),Attribuut:
Public Class Attribuut
Inherits DependencyObject
Public Shared AutonummeringProperty As DependencyProperty = DependencyProperty.Register("Autonummering", GetType(String), GetType(Attribuut))
Public Property Autonummering As String
End Class
那么我如何“反向”绑定单击复选框以将自动编号属性更改为“J”或“N”?
提前致谢
答案 0 :(得分:1)
将IsChecked-Binding上的UpdateSourceTrigger
设置为PropertyChanged
,应该这样做。