9

ScrollViewer内にこのような長方形を作成しました

<ScrollViewer ManipulationMode="Control" x:Name="songScrollViewer"  HorizontalScrollBarVisibility="Visible"  VerticalScrollBarVisibility="Disabled" Height="270" VerticalAlignment="Center" Width="728" Canvas.Top="20" d:LayoutOverrides="HorizontalMargin"   >
  <Rectangle x:Name="musicBG" Fill="#FF0692FD"/>
</ScrollViewer>

アプリの使用中に、MusicBgのサイズが変化し、場合によっては幅が3,000ピクセル程度になります。

musicBG.Width = _songLength*PixelsPerSecond

ただし、scrollViewerをスクロールしている間は、長方形を画面から完全にスクロールできます。

たとえば、このコード行は、長方形を移動したいところまで移動すると、次の値を示します。

if (songScrollViewer.HorizontalOffset > songScrollViewer.ScrollableWidth)

ホリゾンタルオフセットの値は約1200、ScrollableWidthの値は約2900です。

長方形が画面から完全にスクロールされないように、これを適切に行うにはどうすればよいですか?

約1200のHorizo​​ntalOffsetは、長方形を目的地までの約半分だけ押し込み、画面からはみ出さないようにすることを期待します。

答え:

多くのフラストレーションの後、BorderやRectangleの代わりにCanvasを使用することで、この問題を解決することができました。この問題が発生した理由を誰かが説明できる場合、およびキャンバスよりもうまく機能するプロセッサ集約型の制御が少ない場合は、ポイントを付与します。

編集:スクリーンショット:

悪いコード:

<ScrollViewer ManipulationMode="Control" x:Name="songScrollViewer" Width="720"  HorizontalScrollBarVisibility="Visible"  VerticalScrollBarVisibility="Disabled" Height="270" VerticalAlignment="Top" Canvas.Top="20" HorizontalAlignment="Left"   >
                                    <Border x:Name="musicBG"   Background="#FF0692FD" VerticalAlignment="Top" HorizontalAlignment="Left" Height="270" />

            </ScrollViewer>

悪いコードで悪いスクロールの画像: 悪いスクロール

正常に機能するコード:

<ScrollViewer ManipulationMode="Control" x:Name="songScrollViewer" Width="720"  HorizontalScrollBarVisibility="Visible"  VerticalScrollBarVisibility="Disabled" Height="270" VerticalAlignment="Top" Canvas.Top="20" HorizontalAlignment="Left"   >
                <Canvas x:Name="musicBG"  Background ="#FF0692FD" Height="270" >
                    <Border   Background="#FF0692FD" VerticalAlignment="Top" HorizontalAlignment="Left" Height="270" />
                </Canvas>
            </ScrollViewer>

良いスクロール:悪いスクロールの118秒という小さい数字ではなく、右下に170秒と表示されていることに注意してください。 良いスクロール

4

1 に答える 1

1

I believe your right, wp7 won't render shapes that are bigger then 2048 pixels. So the reason it's scrolling of the page is because it's treating it as if it were bigger then 2048 but you can only see up to a width of 2048px and its just scrolling over to the "ghost" part of the rectangle.

I'm not sure if you can override this but the best solution I could come up with (without overriding) is by splitting up your rectangle into chucks that are smaller then 2000 (just to be safe) and then displaying them seamlessly in a horizontal stack panel inside the scroll viewer. The problem with this is that depending on how you've coded it, this solution might be hard to implement; but you might just be able to split it in your ViewModel when displaying it and your logic would only see it as one big chunk.

于 2012-06-27T00:20:30.073 に答える