Converter not called for the last items

Aug 13, 2009 at 11:31 AM

Hi,

I want to use a datatrigger for the template using a conveter. The strange part is that the converter is not called for items that are at the end of the list. I've tested this with a debugger and also by setting the Height value (a condition for the griditem, which was never called when the scrollbar is visible, but was called when all items were visible at the start). When I scroll down I would expect it would be called for the new visible items, but that didn't happen for most of the last items. When the windows is loaded, all visible items are run trough the converter (and some more), when I scroll down the new items are tested as well. But not the last items. When I go up and down with the scroll bar, then the last item will be tested, but never the items before the last. Am I doing something wrong or is this a bug?

This is the xaml code:

<Style TargetType="{x:Type WpfToolkit:DataGridCell}">                               
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource GroupConverter}}" Value="true">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type WpfToolkit:DataGridCell}">                                    
                                        <TextBox Text="{Binding Name, Mode=OneWay}" Background="Green"/>                                        
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource GroupConverter}}" Value="false">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type WpfToolkit:DataGridCell}">                                    
                                        <TextBox Text="{Binding Name, Mode=OneWay}"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

And the converter class:

public class MyGroupConverter : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DataGridCell cell = value as DataGridCell;
            if (cell == null)
                return false;
            GridItem item = cell.DataContext as GridItem;
            if (item == null)
                return false;
            if (Temp.currentModel != null)
            {
                if (item.Level < currentModel.MaxLevel)
                    return true;
                else return false;
            }
            else return false;
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }

    }

Like I said it runs like expected in the top part of the window, but not when I scroll down to the bottom. BTW the values in the converter never reach the null parts.

Thanks for your help,

Frank

Aug 14, 2009 at 1:04 PM

It is even worse. When I edit a griditem, some other item(s) could be changed as well.

I created a demo project. It can be downloaded at http://rapidshare.com/files/267273909/DataGridBug.rar.html

It makes a difference when you change the Height property in the constructor.