This is a migrated thread and some comments may be shown as answers.

[Solved] DataMemberBinding's value converter being called twice!

1 Answer 217 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Justin D.
Top achievements
Rank 1
Justin D. asked on 18 Feb 2011, 12:22 AM
EDIT: To Telerik - My company has purchased the full version of Telerik. I am not using my company account to post here to avoid spam to my work e-mail. If you e-mail me at the address I'm using to post here, I can provide you with our customer ID.

Hello. I have a RadGridView. All of my columns are bound to "normal" properties in the view model, but one property is bound to a converter. The problem is that for each row, the value converter is called twice. (I have a breakpoint in the Convert function of the value converter.) The first time it is called, it passes in the object I expect. The second time it is called, it is passed in null. Any idea why this is happening? It should only be making the first call for each row, where it passes in the object MyClass. It should not be calling it the second time with null as the value. 

I googled this and found something about UpdateSourceTrigger. This did not fix the problem.

Thanks in advance.

<telerik:RadGridView
  x:Name="MyClassGrid"
  IsReadOnly="True"
  MaxHeight="279" 
  Width="1000"
  ItemsSource="{Binding MyClass}"
  IsBusy="{Binding Path=BusyIndicator.IsBusy}"
  IsFilteringAllowed="False"
  ShowGroupPanel="False"
  AutoGenerateColumns="False"
  SelectionUnit="FullRow"
  SelectionMode="Extended"
  RowIndicatorVisibility="Collapsed">
   <telerik:RadGridView.Columns>
       <telerik:GridViewDataColumn Width="70" DataMemberBinding="{Binding DataContext, RelativeSource={RelativeSource Self}, Converter={StaticResource MyValueConverter}}">
          <telerik:GridViewDataColumn.Header>
             <TextBlock Text="Some label here" TextWrapping="Wrap" />
          </telerik:GridViewDataColumn.Header>
       </telerik:GridViewDataColumn>
   </telerik:RadGridView.Columns>
</telerik:RadGridVieW>


1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 22 Feb 2011, 01:57 PM
Hello Justin D.,

Binding to the DataContext, setting your RelativeSource to "Self" mimics a TwoWay binding to the DataContext. In this way the binding is calling your Convert method one time in each direction. With a standard TwoWay binding you can sort UpdateSourceTrigger to Explicitly, but I strongly doubt that this will make any sense in your very case. I would advise you to use this syntax when binding a column of RadGridView to a propery of your business object:

<telerik:GridViewDataColumn  DataMemberBinding="{Binding MyProperty, Converter={StaticResource MyConverter}}"/>

Sincerely,

Ivan Ivanov
the Telerik team

 

Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Justin D.
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or