在silverlight datagrid中的垂直滚动条中出现问题

时间:2013-04-05 06:44:04

标签: silverlight datagrid

我在项目中使用了silverlight datatgrid,并在SelectAll选项的标题中使用了复选框。

在垂直滚动数据网格时,标题复选框状态随机更改,但内容复选框状态仍然正确。

如果有人遇到这个问题,请帮助我。

<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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

这是由于Silverlight的虚拟化使用。

滚动时我遇到了这个问题,网格中的数据在显示方面发生了变化。但实际上它是一样的。事实上,在UI上,silverlight显示错误,因为它在渲染时使用相同的控件。

最好的方法是在datagarid的LoadingRow和UnloadingRow事件中处理你的逻辑。

我在以下链接上发布了一些详细信息:

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