将ScrollViewer分配给网格中的网格

时间:2014-08-20 03:57:29

标签: wpf xaml grid scrollviewer

我有3个网格 - 1个主网格,包含2个子网格。我希望ScrollViewer只出现在一个子网格中。如何才能做到这一点? ScrollViewer要么不显示(设置为自动时),要么显示,但禁用时没有位置指示(设置为可见时)。 我能够将它应用到主网格并且它可以工作,但不能用于子网格。在主网格的情况下,所有高度都设置为自动,因此我假设相同的设置也适用于子网格,但它没有。以下是我的代码摘录:

<UserControl x:Class="StoreMgmtSys.Views.IssueInfoPage" Height="Auto" Width="Auto">
  <Grid x:Name="layoutGridMaster" Height="Auto" Width="Auto" ShowGridLines="False">
    <ScrollViewer CanContentScroll="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
      <Grid x:Name="gridEqpItem" Height="Auto" Grid.Row="0" Grid.Column="0">
      </Grid>       
    </ScrollViewer>
    <Grid x:Name="layoutGridIssue" Grid.Row="0" Grid.Column="1" Margin="0,0,0,0">
    </Grid>
  </Grid>
</UserControl>

编辑 - 想要通过ScrollViewer了解我的网格内容的人的附录:

<ScrollViewer CanContentScroll="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
        <Grid x:Name="gridEqpItem" Background="PaleVioletRed" Height="Auto" Grid.Row="0" Grid.Column="0" Margin="0,0,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <telerik:RadGridView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="2,2,2,0"
                                 x:Name="gridCommsEqp" CanUserDeleteRows="False" ItemsSource="{Binding}"
                                 AutoGenerateColumns="False" CanUserInsertRows="False" MaxHeight="500"
                                 ColumnWidth="Auto" CanUserResizeColumns="False" CanUserResizeRows="True"
                                 HorizontalAlignment="Left" VerticalAlignment="Top" MaxWidth="556"
                                 IsReadOnly="True" SelectionChanged="gridCommsEqp_OnSelectionChanged"
                                 Width="Auto" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed"
                                 FilteringMode="FilterRow" FilterOperatorsLoading="Grid_OnFilterOperatorsLoading">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding CommonDesc}" UniqueName="CommonDesc"
                                                TextWrapping="Wrap" Width="190" TextAlignment="Center">
                        <telerik:GridViewDataColumn.Header>
                            <TextBlock Text="Equipment" TextAlignment="Center" />
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding OtherKeywords}"
                                                UniqueName="OtherKeywords"
                                                TextWrapping="Wrap" Width="210" TextAlignment="Center">
                        <telerik:GridViewDataColumn.Header>
                            <TextBlock Text="Keywords" TextAlignment="Center" />
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding CurrentQty}" MaxWidth="73"
                                                TextAlignment="Center"
                                                UniqueName="CurrentQty" TextWrapping="Wrap">
                        <telerik:GridViewDataColumn.Header>
                            <TextBlock Text="Current Quantity" TextWrapping="Wrap" TextAlignment="Center" />
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding TotalQty}" TextAlignment="Center"
                                                UniqueName="TotalQty" TextWrapping="Wrap" MaxWidth="73">
                        <telerik:GridViewDataColumn.Header>
                            <TextBlock Text="Total Quantity" TextWrapping="Wrap" TextAlignment="Center" />
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
            <telerik:RadListBox Margin="5,5,5,0" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2"
                                x:Name="listBoxItems" HorizontalAlignment="Left" VerticalAlignment="Top"
                                Width="250" SelectionMode="Multiple" Visibility="Collapsed" 
                                TextPath="Serial" MaxHeight="400" Background="Transparent"
                                ItemContainerStyle="{StaticResource MetroListBoxItem}"
                                SelectionChanged="ListBoxItems_OnSelectionChanged">
                <telerik:RadListBox.DragVisualProvider>
                    <telerik:ScreenshotDragVisualProvider />
                </telerik:RadListBox.DragVisualProvider>
                <telerik:RadListBox.DragDropBehavior>
                    <telerik:ListBoxDragDropBehavior />
                </telerik:RadListBox.DragDropBehavior>
                <telerik:RadListBox.DataConverter>
                    <storeMgmtSys:ItemToIssueConverter />
                </telerik:RadListBox.DataConverter>
                <telerik:RadListBox.AllowDrop>False</telerik:RadListBox.AllowDrop>
            </telerik:RadListBox>
            <telerik:RadGridView Grid.Row="1" Grid.Column="1" Margin="0,5,5,0"
                                 FontWeight="Bold" FontSize="14"
                                 x:Name="gridCommsEqpSet" CanUserDeleteRows="False" ItemsSource="{Binding}"
                                 AutoGenerateColumns="False" CanUserInsertRows="False" MaxHeight="400"
                                 Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top"
                                 ColumnWidth="Auto" CanUserResizeColumns="False" CanUserResizeRows="True"
                                 MaxWidth="300" Width="Auto" ShowGroupPanel="False" SelectionMode="Single"
                                 RowIndicatorVisibility="Collapsed" Visibility="Collapsed"
                                 SelectionChanged="GridCommsEqpSet_OnSelectionChanged"
                                 FilterOperatorsLoading="Grid_OnFilterOperatorsLoading">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" UniqueName="Description"
                                                TextWrapping="Wrap" Header="SELECT A SET" Width="Auto"
                                                MaxWidth="200" HeaderTextAlignment="Center"
                                                IsReadOnly="True" TextAlignment="Center"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
            <telerik:RadListBox Margin="0,5,5,0" Grid.Column="1" Grid.Row="2"
                                x:Name="listBoxSetItems" HorizontalAlignment="Left" VerticalAlignment="Top"
                                Width="250" ItemContainerStyle="{StaticResource MetroListBoxItem}"
                                SelectionMode="Multiple" Background="Transparent"                                    
                                TextPath="Serial" MaxHeight="400" Visibility="Collapsed">
                <telerik:RadListBox.DragVisualProvider>
                    <telerik:ScreenshotDragVisualProvider />
                </telerik:RadListBox.DragVisualProvider>
                <telerik:RadListBox.DragDropBehavior>
                    <telerik:ListBoxDragDropBehavior />
                </telerik:RadListBox.DragDropBehavior>
                <telerik:RadListBox.DataConverter>
                    <storeMgmtSys:ItemToIssueConverter />
                </telerik:RadListBox.DataConverter>
                <telerik:RadListBox.AllowDrop>False</telerik:RadListBox.AllowDrop>
            </telerik:RadListBox>
            <Label Grid.Column="0" Grid.Row="3" Margin="5,5,5,5" VerticalAlignment="Top" HorizontalAlignment="Left"
                   Content="Issue Date" FontWeight="Bold" Foreground="#FF008BFF" FontSize="14" />
            <Label Grid.Column="0" Grid.Row="4" Margin="5,0,5,5" VerticalAlignment="Top" HorizontalAlignment="Left"
                   Content="Receipt Date" FontWeight="Bold" Foreground="#FF008BFF" FontSize="14" />
            <telerik:RadDatePicker Grid.Column="0" Grid.Row="3" Margin="98,5,0,0"
                                   HorizontalAlignment="Left" VerticalAlignment="Top"
                                   x:Name="issueDate" Height="30" Width="155"
                                   SelectionChanged="issueDate_SelectionChanged" />
            <telerik:RadDatePicker Grid.Column="0" Grid.Row="4" Margin="98,0,0,0"
                                   HorizontalAlignment="Left" VerticalAlignment="Top"
                                   x:Name="receiptDate" Height="30" Width="155"
                                   SelectionChanged="receiptDate_SelectionChanged"/>
        </Grid>
    </ScrollViewer>

1 个答案:

答案 0 :(得分:0)

终于解决了我的问题。问题在于我的主网格的RowDefinition(我没有在我的问题中透露代码)。诀窍是将第一个RowDefinition高度设置为&#34; *&#34;如下所示。最初我的代码是&#34; Auto&#34;。不要问我为什么;我不知道如何解释,因为我的编程概念还不是很好。

<Grid x:Name="layoutGridMaster" Height="Auto" Width="Auto" ShowGridLines="False">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  .
  .
  .
</Grid>