Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Converter and databinding

Sort Posts: Previous Next
  •  06-13-2008, 10:24 AM Post no. 12944

    Converter and databinding

    Hey guys please help me here. Im using a converter to bind to an enumeration with a three state checkbox. I have a 3 value enumeration, Allowed, Denied, and Unassigned. I have a custom styled checkbox that is red, green, and yellowe depending on the bound value of the enumeration. However I cannot get this to update the property on my bound object when i change the value of the checkbox. The very weird thing is I can get it to work (which is not an option i can use).  If I dont use a celleditor template and just define a cellcontent template, then the editor by default is a text value -- if i type in the enumeration and hit enter or click on another row to call EndEdit then i can see the changes reflected in my business objects bound PrivilegeStatus property. However (and ive tried like 5 different combinations or things) when I define a celleditor template with a checkbox then the property is never updated after the EndEdit. Very strange. Ive also looked at changing the return values for my ConvertBack function in my converter, to no avail. I will past the code for my converter and then for my datatemplates. Someone here please help! :)

     

    This is the setup where I can edit the text and type in the correct enum value and it works, but this is not an option i can take.

    <xcdg:Column Title="Privilege Status" FieldName="UserPrivilegeStatus" ReadOnly="False" >

    <xcdg:Column.CellContentTemplate>

    <DataTemplate>

     

    <CheckBox Style="{DynamicResource PrivilegeCheckbox}" IsThreeState="True" IsChecked="{Binding Path=.,Converter={StaticResource StatusConverter},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

     

    </DataTemplate>

    </xcdg:Column.CellContentTemplate>

    <!--<xcdg:Column.CellEditor>

    <xcdg:CellEditor>

    <xcdg:CellEditor.EditTemplate>

    <DataTemplate>

     

    <CheckBox Style="{DynamicResource PrivilegeCheckbox}"  IsThreeState="True" IsChecked="{Binding Path=.,Converter={StaticResource StatusConverter},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

    </DataTemplate>

    </xcdg:CellEditor.EditTemplate>

    </xcdg:CellEditor>

    </xcdg:Column.CellEditor>-->

    </xcdg:Column>

     

     

    Heres my converter code

    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) And (CType(value, String) <> "") Then

    Dim status As Common.Enums.PrivilegeStatus = CType(value, Common.Enums.PrivilegeStatus)

    Select Case status

    Case Common.Enums.PrivilegeStatus.Allowed

    Return True

    Case Common.Enums.PrivilegeStatus.Denied

    Return False

    Case Common.Enums.PrivilegeStatus.Unassigned

    Return Nothing

    Case Else

    Return Nothing

    End Select

    Else

    Return Nothing

    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 value Is Nothing Then

    Return Common.Enums.PrivilegeStatus.Unassigned

    Else

    If CType(value, Boolean) = False Then

    Return Common.Enums.PrivilegeStatus.Denied

    Else

    Return Common.Enums.PrivilegeStatus.Allowed

    End If

    End If

    Throw New Exception("Cannot convert back")

    End Function

     

     

    Any help is greatly appreciated!

     

    Thanks

    Justin Coon

  •  06-14-2008, 8:07 AM Post no. 12964 in reply to 12944

    Re: Converter and databinding

    In your EditTemplate, you need to use a CellEditorBinding to bind the value of the IsChecked property.

    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  06-16-2008, 10:26 AM Post no. 12992 in reply to 12964

    Re: Converter and databinding

    Jenny thank you so much for your reply. This is for a project at work, which im kind of stuck till I can get past this. I looked at the documentation examples and its still a little fuzzy to me. Here is what i have and it still is not updating the privilegestatus property in my bound object.

     

    <xcdg:Column Title="Privilege Status" FieldName="UserPrivilegeStatus" ReadOnly="False" >

    <xcdg:Column.CellContentTemplate>

    <DataTemplate>

     

    <CheckBox Style="{DynamicResource PrivilegeCheckbox}" IsThreeState="True" IsChecked="{Binding Path=.,Converter={StaticResource StatusConverter},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

     

    </DataTemplate>

    </xcdg:Column.CellContentTemplate>

    <xcdg:Column.CellEditor>

    <xcdg:CellEditor>

    <xcdg:CellEditor.EditTemplate>

    <DataTemplate>

     

    <CheckBox Style="{DynamicResource PrivilegeCheckbox}" IsThreeState="True" IsChecked="{Binding xcdg:CellEditorBinding,Converter={StaticResource StatusConverter},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

    </DataTemplate>

    </xcdg:CellEditor.EditTemplate>

    </xcdg:CellEditor>

    </xcdg:Column.CellEditor>

    </xcdg:Column>

     

    Any thoughts? I must be doing something wrong ....

  •  06-16-2008, 10:43 AM Post no. 12993 in reply to 12992

    Re: Converter and databinding

    Hey Jenny I think I got it. :)

    IsChecked="{xcdg:CellEditorBinding Converter={StaticResource StatusConverter}}"

     

    I think thats working. Thank you so much for your help it is greatly appreciated. Also thank you for being so active in the forums its so helpful. I see you answering many many posts.

     

    Justin

  •  09-03-2008, 12:32 PM Post no. 14847 in reply to 12993

    Re: Converter and databinding

    Hi,

     how do I have to write ConverterParameter?

  •  09-03-2008, 2:35 PM Post no. 14853 in reply to 14847

    Re: Converter and databinding

    No. You do not need to write a converter parameter. Whatever you put there (for example "HelloWorld") will appear as the "parameter" parameter in  your converter's Convert method.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  09-03-2008, 9:44 PM Post no. 14869 in reply to 14853

    Re: Converter and databinding

    for example

     

    <TextBlock Text="{Binding Path=SomeProperty, Converter={StaticResource aConverter}, ConverterParameter='a string parameter to pass to the converter'}" />

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.