1

I'm using a silverlight datatgrid in my project with checkbox in the header for SelectAll option.

While scrolling the datagrid vertically, the header checkbox status is changing randomly but the content checkbox status is remains correct.

Please help me if anyone come across this issue.

<control:DataGrid.RowGroupHeaderStyles>
   <Style TargetType="control:DataGridRowGroupHeader">
         <Setter Property="PropertyNameVisibility" Value="Collapsed" />
         <Setter Property="Background" Value="LightGray" />
         <Setter Property="Foreground" Value="#FF404040" />
         <Setter Property="SublevelIndent" Value="15" />
         <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="control:DataGridRowGroupHeader">
                  <Primitives:DataGridFrozenGrid Name="Root" Background="{TemplateBinding Background}">
                     <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CurrentStates">
                           <VisualState x:Name="Regular"/>
                              <VisualState x:Name="Current">
                               <Storyboard>
                               <DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                </Storyboard>
                             </VisualState>
                         </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Primitives:DataGridFrozenGrid.Resources>
                          <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
                          <Grid Background="Transparent">
                               <VisualStateManager.VisualStateGroups>
                                  <VisualStateGroup x:Name="CommonStates">
                                     <VisualState x:Name="Normal"/>
                                       <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>
                                      </VisualState>
                                     <VisualState x:Name="Pressed">
                                       <Storyboard>
                                         <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" Duration="0" To="#FF6DBDD1"/>

                                                <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>
                                    </Primitives: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="#FFFDD234" Height="1"/>
                                    <Rectangle Grid.Column="1" Grid.Row="1" Name="IndentSpacer" />
                                    <ToggleButton Grid.Column="2" Grid.Row="1" Name="ExpanderButton" Height="15" Width="15" IsTabStop="False" 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 Tag="{Binding}" Name="headerCheck" Click="headerCheck_Click"  HorizontalAlignment="Left"   />
                                    </StackPanel>

                                    <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FF4F54DA" Height="1" Grid.Row="2"/>
                                    <Rectangle Name="FocusVisual" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="3" Stroke="#FF6DB112" StrokeThickness="1" HorizontalAlignment="Stretch" 
                           VerticalAlignment="Stretch" IsHitTestVisible="false" Opacity="0" />
                                    <Primitives:DataGridRowHeader Name="RowHeader" Grid.RowSpan="3" Primitives:DataGridFrozenGrid.IsFrozen="True" />

                                </Primitives:DataGridFrozenGrid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </control:DataGrid.RowGroupHeaderStyles>
4

2 回答 2

0

It is due to virtualization usage by Silverlight.

I came across this problem when you scroll, data within the grid changes in terms of display. But in actuality it is the same. It is just a fact that on UI, silverlight shows it incorrectly because it uses the same controls while rendering.

The best way is to handle your logic inside LoadingRow and UnloadingRow events of the datagarid.

I have some detail posted on the following link:

https://stackoverflow.com/a/25566163/3989725

于 2014-08-29T10:33:34.303 回答
0

您将标题复选框绑定到当前项目,并且当您滚动它时它会发生变化。除非您使用 setter 更改 ItemsSource 集合中的所有值,否则我不会将此复选框绑定到任何内容。在这种情况下,请确保没有其他任何东西改变它所绑定的属性的值。

于 2013-04-08T19:26:17.263 回答