2016-06-03 1 views
1

J'ai un problème avec un ScrollViewer dans WPF.Problème avec WPF ScrollViewer redimensionner

Lorsqu'une fenêtre est dimensionnée au point où le ScrollViewer doit commencer à prendre le relais, la fenêtre ne redimensionne pas la grille contenant et le bas de la barre de défilement ne s'affiche pas.

J'ai essayé de relier la hauteur à la hauteur de la grille contenant, mais sans succès.

Voici mon XAML:

<Grid x:Name="MainGrid" Width="Auto" Height ="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <StackPanel Height="134" Width="Auto" VerticalAlignment="Top" Background="Blue" HorizontalAlignment="Stretch"> 
     <Label x:Name="ProjectNumberLabel" Content="ProjectNumber" HorizontalAlignment="Left" Height="45.5" VerticalAlignment="Top" Width="350" FontSize="32" Margin="10,0,0,0" Foreground="White"/> 

     <Label x:Name="ProjectNameLabel" Content="ProjectName" HorizontalAlignment="Stretch" Height="42" VerticalAlignment="Top" FontSize="24" Margin="10,0,0,0" Foreground="White" Width="auto"/> 

     <Label x:Name="SetLabel" Content="Set Id" HorizontalAlignment="Stretch" Width="Auto" Height="42" Margin="10,0,10,0" FontSize="24" VerticalAlignment="Top" Foreground="White" /> 

    </StackPanel> 

    <ScrollViewer HorizontalAlignment="Stretch" Margin="0,140,0,0" Width="Auto" CanContentScroll="True" Height="{Binding ElementName=MainGrid, Path=ActualHeight }"> 
     <StackPanel Name="ContainingPanel" VerticalAlignment="Top" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"> 
      <StackPanel HorizontalAlignment="Stretch" Width="Auto" Height="300"/> 

      <StackPanel HorizontalAlignment="Stretch" Height="38" VerticalAlignment="Bottom"> 
       <CheckBox x:Name="ComplexDataCheckBox" Content="Show All Data" Click="ComplexDataCheckBox_Click" RenderTransformOrigin="1.751,0.547" Margin="0,4,0,0" Height="16" HorizontalAlignment="Right" Width="105" VerticalAlignment="Bottom"> 
        <CheckBox.LayoutTransform> 
         <ScaleTransform ScaleX="2" ScaleY="2" /> 
        </CheckBox.LayoutTransform> 
       </CheckBox> 
      </StackPanel> 

      <StackPanel HorizontalAlignment="Stretch"> 
         <syncfusion:SfDataGrid HorizontalAlignment="Stretch" Width="Auto" VerticalAlignment="Stretch" x:Name="SpecimenGrid" AutoGenerateColumns="True" RowStyleSelector="{StaticResource styleselector}"/> 
      </StackPanel> 

     </StackPanel> 
    </ScrollViewer> 
</Grid> 
+0

En voyant comment vous placez vos composants, la grille extérieure est inutile, un 'DockPanel' aurait beeen suffisante. Pour placer d'autres contrôles dans une grille, vous devez définir 'ColumnDefinitions' et' RowDefinitions'. Quant à 'ScrollViewer', ne définissez pas sa hauteur, mais définissez' VerticalAlignement' pour l'étirer. La barre de défilement apparaîtra une fois que le contenu ne sera plus ajusté – Sidewinder94

Répondre

4

si ScrollViewer a une hauteur égale à la hauteur de grille et pas la marge zéro verticale, il sort des limites de la grille.

il est préférable de mettre StackPanel et ScrollViewer en deux rangées de grilles séparées:

<Grid x:Name="MainGrid"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="140"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <StackPanel Grid.Row="0"> 
     <!--Content--> 
    </StackPanel> 

    <ScrollViewer Grid.Row="1" 
        HorizontalAlignment="Stretch" 
        Margin="0" 
        CanContentScroll="True" > 
     <!--Content--> 
    </ScrollViewer> 
</Grid> 
+0

J'ai essayé ce que vous avez suggéré et il semble que la hauteur de ScrollViewer veuille toujours correspondre à son contenu et non au conteneur Grid Row dans lequel il est. – laxin204

+0

les choses étaient contenues à l'intérieur d'un autre StackPanel, Ichanged cela à une grille aussi et le problème est maintenant corrigé. Merci beaucoup pour votre aide – laxin204