1

我有一个 Silverlight 数据网格,它应用了 RowStyle 来突出显示某些行。屏幕上无法容纳的列数,因此有一个水平滚动条。但是,当向右滚动时,数据列很快就会与标题不同步。

我通过将样式定义直接移动到 XAML 中的数据网格代码中尝试了此处建议的解决方案,但这对我不起作用。我知道是风格导致了问题,但我无法确定罪魁祸首是哪一部分!我在下面提供了样式和数据网格定义。任何建议,将不胜感激!

<sdk:DataGrid MinHeight="100" Margin="0,0,0,30" AutoGenerateColumns="False" Name="dgResults" ItemsSource="{Binding Path=FindResults}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}"
                                    RowStyle="{StaticResource RowColorableDataGrid}" toolkit:DockPanel.Dock="Bottom">
                        <i:Interaction.Behaviors>
                            <behavior:SelectRowOnRightClickBehavior />
                            <mybehavior:DepartureContextMenuBehavior/>
                        </i:Interaction.Behaviors>
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTemplateColumn CanUserReorder="False" CanUserResize="True" CanUserSort="False" Header="Select">
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox ClickMode="Press" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" Width="Auto" IsEnabled="True"/>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>
                            <sdk:DataGridTextColumn Header="Code" Binding="{Binding Path=Tourcode}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Tour" Binding="{Binding Path=TourDescription}" IsReadOnly="True" Width="200" />
                            <sdk:DataGridTextColumn Header="Brand" Binding="{Binding Path=Brand}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Land Start Date" Binding="{Binding Path=LandStartDate}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Land End Date" Binding="{Binding Path=LandEndDate}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Status" Binding="{Binding Path=Status}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="TIP Avail" Binding="{Binding Path=Availability}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="GSpace" Binding="{Binding Path=GSpace}" IsReadOnly="True" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Per PAX (TWN)" Binding="{Binding Path=PricePerPaxTwin}" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Per PAX (SGL)" Binding="{Binding Path=PricePerPaxSingle, StringFormat='+0;-0;0'}" Width="Auto" />
                            <sdk:DataGridTextColumn Header="Per PAX (TPL)" Binding="{Binding Path=PricePerPaxTriple, StringFormat='+0;-0;0'}" Width="Auto" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>

这是 RowStyle XAML:

<Style TargetType="data:DataGridRow" x:Key="RowColorableDataGrid">
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="data:DataGridRow">
                    <localprimitives:DataGridFrozenGrid x:Name="Root">
                        <localprimitives:DataGridFrozenGrid.Resources>
                            <Storyboard x:Key="DetailsVisibleTransition">
                                <DoubleAnimation Duration="00:00:0.1" Storyboard.TargetName="DetailsPresenter" Storyboard.TargetProperty="ContentHeight"/>
                            </Storyboard>
                        </localprimitives:DataGridFrozenGrid.Resources>
                        <localprimitives:DataGridFrozenGrid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </localprimitives:DataGridFrozenGrid.RowDefinitions>
                        <localprimitives:DataGridFrozenGrid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </localprimitives:DataGridFrozenGrid.ColumnDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="NormalAlternatingRow">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" To=".5"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="NormalSelected">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOverSelected">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="UnfocusedSelected">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Fill).Color" To="#FFE1E7EC"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid"/>

                                <VisualState x:Name="Invalid">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="InvalidVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="BackgroundRectangle" Fill="{Binding RowBackgroundColor, Mode=OneWay}" Grid.ColumnSpan="2" Grid.RowSpan="2"/>
                        <Rectangle x:Name="InvalidVisualElement" Fill="#FFF7D8DB" Opacity="0" Grid.ColumnSpan="2" Grid.RowSpan="2"/>
                        <localprimitives:DataGridRowHeader x:Name="RowHeader" localprimitives:DataGridFrozenGrid.IsFrozen="True" Grid.RowSpan="3"/>
                        <ContentControl x:Name="contentControl" Foreground="{Binding RowForegroundColor, Mode=OneWay}">
                            <localprimitives:DataGridCellsPresenter x:Name="CellsPresenter" localprimitives:DataGridFrozenGrid.IsFrozen="True" Grid.Column="1"/>
                        </ContentControl>
                        <localprimitives:DataGridDetailsPresenter x:Name="DetailsPresenter" Grid.Column="1" Grid.Row="1"/>
                        <Rectangle x:Name="BottomGridLine" Height="1" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="2"/>
                    </localprimitives:DataGridFrozenGrid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
4

0 回答 0