2016-08-27 8 views
1

Canvasに入れようとしていますが、スクロールが機能しません。ScrollViewerがキャンバス内で動作しません

<Page 
    x:Class="ScrollViewerInCanvas.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:ScrollViewerInCanvas" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Canvas> 
     <ScrollViewer> 
     <StackPanel Orientation="Vertical" Width="400"> 
      <TextBlock Text="Just a huge text that will not fit into a single frame" 
        FontSize="100" TextWrapping="WrapWholeWords" /> 
     </StackPanel> 
     </ScrollViewer> 
    </Canvas> 
    </Grid> 
</Page> 

しかし、私はCanvasGridすべての作品切り替えた場合。 ScrollViewerCanvasの内部で処理する方法はありますか?

+0

@PeterDunihoこれは実際に私の問題を再現する最小の例でした。キャンバスの仕組みが誤解されていたことが問題の原因でした。私の質問に対する答えは、実際に私が必要としていたものです。回答の一部をCanvasが "Answers"にどのように作用するのかを記述してください。私はそれを私の質問の答えとしてマークします。 – Geslot

+0

さて、完了。あなたの質問に編集したコード例に注目してください。これは、質問の理解度と再現性を確保するために必要なコード例です。詳細については、[記事の最後のリンクを含む] [mcve]を参照してください。 –

答えて

1

投稿に含まれているコードに基づいて、ScrollViewerにスクロールが必要な理由は表示されません。 Canvas要素は、いかなる形でもその子要素を制約しません。従ってCanvasでは、ScrollViewerは望みの大きさにすることができます。そのため、スクロールせずに子を格納するのに十分な大きさになります。 Gridでは、そのセルに収まるように引き伸ばされているので、セルが子供よりも小さい場合、スクロールが可能になります。スクロールする理由を付けてください。その原因となるコンテンツのサイズよりも小さいものにScrollViewerのサイズを制約するだろう

<Page 
    x:Class="ScrollViewerInCanvas.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:ScrollViewerInCanvas" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Canvas x:Name="canvas1"> 
     <ScrollViewer Width="{Binding ActualWidth, ElementName=canvas1}" 
        Height="{Binding ActualHeight, ElementName=canvas1}"> 
     <StackPanel Orientation="Vertical" Width="400"> 
      <TextBlock Text="Just a huge text that will not fit into a single frame" 
        FontSize="100" TextWrapping="WrapWholeWords" /> 
     </StackPanel> 
     </ScrollViewer> 
    </Canvas> 
    </Grid> 
</Page> 

何か:

たとえば、あなたはScrollViewerは常にそのCanvas親と同じ大きさも作ることができますスクロールバーを表示して使用可能にします。

+0

ありがとう、これは私が必要としていたものです! – Geslot

関連する問題