2011-04-28 65 views
2

我有一个DatagridTemplate列包含一个复选框,当我的ItemSource属性是“J”时通过转换器得到检查,并且当属性是“N”时取消选中。WPF DataGridTemplateColumn复选框元素IsChecked与转换器TwoWay绑定

这是有效的,但现在我希望将属性设置为“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> 

我的转换器:

公共类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 

末级

我的ItemSource是一个List(中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 

那么,我将如何“反向”绑定点击复选框将Autonummering属性更改为“J”或“N”?

在此先感谢

+0

您的转换器不工作吗? – 2011-04-28 19:17:28

+0

我猜不是!?... – 2011-04-28 19:37:58

回答

1

坐落在器isChecked-绑定到PropertyChangedUpdateSourceTrigger,应该这样做。

+0

那就是问题所在!谢谢。 – 2011-04-28 21:55:09

+0

很高兴帮助:) – 2011-04-28 21:59:44

相关问题