locked
RowgroupHeader Checkbox: Scrolling Bug RRS feed

  • Question

  • Hello,

    I have a Problem which was asked and answered in the past, but I didnt find an answer (dead links in https://social.msdn.microsoft.com/Forums/en-US/b6571cc5-a3aa-4e55-968a-b117081b6d87/checkbox-visual-bug-in-a-datagrid-rowgroupheaderstyle?forum=silverlightcontrols or http://www.busydevelopers.com/article/43570192/Customizing+Silverlight+Datagrid+row+groupheader )

     if I check one Checkbox in a DataGrid RowGroupHeader, other (not visible) checkboxes get checked when I scroll down. How to prevent this? My DataGrid Looks like this:

     <sdk:DataGrid Name="dg_XMLEventLogs" AutoGenerateColumns="False" 
                                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,88,0,33" >
    
                        <sdk:DataGrid.RowGroupHeaderStyles>
                            <Style TargetType="sdk:DataGridRowGroupHeader">
                                <Setter Property="Cursor" Value="Arrow" />
                                <Setter Property="IsTabStop" Value="False" />
                                <Setter Property="Background" Value="#FFE4E8EA" />
                                <Setter Property="Height" Value="20"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="sdk:DataGridRowGroupHeader">
                                            <sdk:DataGridFrozenGrid Name="Root" Background="{TemplateBinding Background}" ShowGridLines="False">
                                                <vsm:VisualStateManager.VisualStateGroups>
                                                    <vsm:VisualStateGroup x:Name="CurrentStates">
                                                        <vsm:VisualState x:Name="Regular"/>
                                                        <vsm:VisualState x:Name="Current">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                    </vsm:VisualStateGroup>
                                                </vsm:VisualStateManager.VisualStateGroups>
                                                <sdk:DataGridFrozenGrid.Resources>
                                                    <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
                                                        <Grid Background="Transparent">
                                                            <vsm:VisualStateManager.VisualStateGroups>
                                                                <vsm:VisualStateGroup x:Name="CommonStates">
                                                                    <vsm:VisualState x:Name="Normal"/>
                                                                    <vsm:VisualState x:Name="MouseOver">
                                                                        <Storyboard>
                                                                            <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" Duration="0" To="#FF6DBDD1"/>
                                                                            <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/>
                                                                        </Storyboard>
                                                                    </vsm:VisualState>
                                                                    <vsm:VisualState x:Name="Pressed">
                                                                        <Storyboard>
                                                                            <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" Duration="0" To="#FF6DBDD1"/>
                                                                            <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/>
                                                                        </Storyboard>
                                                                    </vsm:VisualState>
                                                                    <vsm:VisualState x:Name="Disabled">
                                                                        <Storyboard>
                                                                            <DoubleAnimation Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Opacity" To=".5"/>
                                                                            <DoubleAnimation Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Opacity" To=".5"/>
                                                                        </Storyboard>
                                                                    </vsm:VisualState>
                                                                </vsm:VisualStateGroup>
                                                                <vsm:VisualStateGroup x:Name="CheckStates">
                                                                    <vsm:VisualState x:Name="Checked" />
                                                                    <vsm:VisualState x:Name="Unchecked">
                                                                        <Storyboard>
                                                                            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Visibility">
                                                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                                                                            </ObjectAnimationUsingKeyFrames>
                                                                            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Visibility">
                                                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                                                            </ObjectAnimationUsingKeyFrames>
                                                                        </Storyboard>
                                                                    </vsm:VisualState>
                                                                </vsm:VisualStateGroup>
                                                            </vsm:VisualStateManager.VisualStateGroups>
    
                                                            <Path Stretch="Uniform" Data="F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z" Width="5" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="CollapsedArrow" Visibility="Collapsed" Stroke="#FF414345"/>
                                                            <Path Stretch="Uniform" Data="F1 M 0,1 L 1,1 L 1,0 L 0,1 Z" Width="6" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="ExpandedArrow" Fill="#FF414345"/>
                                                        </Grid>
                                                    </ControlTemplate>
                                                </sdk:DataGridFrozenGrid.Resources>
    
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
    
                                                <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFFFFFFF" Height="1"/>
                                                <Rectangle Grid.Column="1" Grid.Row="1" Name="IndentSpacer" />
                                                <ToggleButton Grid.Column="2" Grid.Row="1" Name="ExpanderButton" Height="15" Width="15" Template="{StaticResource ToggleButtonTemplate}" Margin="2,0,0,0"/>
    
                                                <StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,0,1">
                                                    <CheckBox Content="{Binding Name}" ClickMode="Press" Margin="25,0" 
                                                              Checked="chkAll_Checked" Unchecked="chkAll_UnChecked" />
                                                    <!--<TextBlock x:Name="PropertyNameElement" Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}"/>
                                                    <TextBlock Margin="4,0,0,0" Text="{Binding Name}" />
                                                    <TextBlock x:Name="ItemCountElement" Margin="4,0,0,0" Visibility="{TemplateBinding ItemCountVisibility}"/>-->
                                                </StackPanel>
                                                <TextBlock Grid.Column="4" Grid.Row="1" Text="Right Align" HorizontalAlignment="Right"/>
                                                <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFD3D3D3" Height="1" Grid.Row="2"/>
                                                <Rectangle Name="FocusVisual" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="3" Stroke="#FF6DBDD1" StrokeThickness="1" HorizontalAlignment="Stretch" 
                       VerticalAlignment="Stretch" IsHitTestVisible="false" Opacity="0" />
                                                <sdk:DataGridRowHeader Name="RowHeader" Grid.RowSpan="3" sdk:DataGridFrozenGrid.IsFrozen="True"/>
    
                                            </sdk:DataGridFrozenGrid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </sdk:DataGrid.RowGroupHeaderStyles>
                        <sdk:DataGrid.Columns>
    ...

    Friday, November 18, 2016 9:37 AM

Answers

  • After half a year I finally found my solution. The Magic word is: BINDING!
    The difficulty was to find the "Items" Keyword to bind to and writing a Converter.

    In my RowGroupHeader-Template:

                                                <StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,0,1">
                                                    <CheckBox ClickMode="Press" Margin="25,0" 
                                                              IsChecked="{Binding Items, Converter={StaticResource NoUnchecked}}" />
                                                    <!--<TextBlock x:Name="PropertyNameElement" Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}"/>-->
                                                    <TextBlock Margin="4,0,0,0" Text="{Binding Name}" />
                                                    <TextBlock x:Name="ItemCountElement" Margin="4,0,0,0" Visibility="{TemplateBinding ItemCountVisibility}"/>
                                                </StackPanel>

    The needed Converter:

        public class NoUnchecked : DependencyObject, IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                System.Collections.ObjectModel.ReadOnlyObservableCollection<object> items = value as System.Collections.ObjectModel.ReadOnlyObservableCollection<object>;
                return !items.Cast<...>().Where(p => p.SelectedToCopy == false).Any();
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    • Marked as answer by Quidnunc1987 Friday, August 18, 2017 12:30 PM
    Friday, August 18, 2017 12:27 PM

All replies


  • Hi Quidnunc1987,

    >>if I check one Checkbox in a DataGrid RowGroupHeader, other (not visible) checkboxes get checked when I scroll down. How to prevent this?

    Do you check the checkbox in a DataGrid RowGroupHeader and when you scroll down the DataGrid, CheckBox for some other group's also get checked? or do you want select only shows in DataGrid?

    I suggest you can upload your demo to OneDrive(Including your test material). We can download it and debugging. You can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages. This will help us quickly analyze your problem.

    Share OneDrive files and folders:
    https://support.office.com/en-us/article/Share-OneDrive-files-and-folders-9fcc2f7d-de0c-4cec-93b0-a82024800c07

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 21, 2016 10:00 AM
  • Hi Quidnunc1987,

    As far as I know, the function for checkbox in RowGroupHeader is used to check all checkboxes in DataGride, which contains all of them, include the not visible checkboxes. It is based on the code in your chkAll_Checked event.

    So if you just want to check the visible checkboxes, you need to modify the chkAll_Checked event code. In chkAll_Checked event, you need to judge which records are visible in DataGrid and then loop these records to check them only.

    But I think check all checkboxes include not visible checkboxed is more appropriate. 

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 22, 2016 9:11 AM
    Moderator
  • I'm sorry, I have to correct my sentence so ist clear what I mean: 

    if I check one Checkbox in a DataGrid RowGroupHeader, other (not visible) checkboxes IN OTHER ROWGROUPHEADERS get checked. It is a display bug while scrolling.

    Nothing to do with my chkAll_Checked.

    In ListBoxes theres some similar bug with normal Items, here you can prevent it by adding XAML:

    <ListBox.ItemsPanel>
      <ItemsPanelTemplate>
         <StackPanel />
      </ItemsPanelTemplate>
    <ListBox.ItemsPanel>
    But for DataGrid I didn't find a solution.

    Monday, November 28, 2016 10:04 AM
  • Hi Quidnunc1987,

    Sorry for misunderstanding your issue before.

    I have reproduce your problem and find that when I checked one of the Checkbox, other checkbox's Click event is not invoked. So this issue only related to the Silverlight DataGrid display mechanism.

    And there has other communities has the same issue, and the solution that he/she used is add a new property in your data source: IsSelected, and to bind the checkbox to that value. Then we can use this value to control the Checkbox checked or not.

    https://social.msdn.microsoft.com/Forums/silverlight/en-US/06b36cb1-a97c-46c6-872c-ae00e2102877/in-datagrid-select-all-checkbox-and-scrolling-the-selected-checkbox-will-be-unchecked?forum=silverlightbugs#501008

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 29, 2016 5:01 AM
    Moderator
  • Thats not the same problem. In your link the problem is in a NORMAL ROW.

    In my case, it's in a GROUP ROW! And a group doesn't have a property I can bind to.

    Wednesday, December 7, 2016 8:05 AM
  • After half a year I finally found my solution. The Magic word is: BINDING!
    The difficulty was to find the "Items" Keyword to bind to and writing a Converter.

    In my RowGroupHeader-Template:

                                                <StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,0,1">
                                                    <CheckBox ClickMode="Press" Margin="25,0" 
                                                              IsChecked="{Binding Items, Converter={StaticResource NoUnchecked}}" />
                                                    <!--<TextBlock x:Name="PropertyNameElement" Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}"/>-->
                                                    <TextBlock Margin="4,0,0,0" Text="{Binding Name}" />
                                                    <TextBlock x:Name="ItemCountElement" Margin="4,0,0,0" Visibility="{TemplateBinding ItemCountVisibility}"/>
                                                </StackPanel>

    The needed Converter:

        public class NoUnchecked : DependencyObject, IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                System.Collections.ObjectModel.ReadOnlyObservableCollection<object> items = value as System.Collections.ObjectModel.ReadOnlyObservableCollection<object>;
                return !items.Cast<...>().Where(p => p.SelectedToCopy == false).Any();
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    • Marked as answer by Quidnunc1987 Friday, August 18, 2017 12:30 PM
    Friday, August 18, 2017 12:27 PM