私はこれを機能させるのに多くの問題を抱えており、誰かが助けてくれることを望んでいました。
WindowsPhoneアプリにScrollViewerがあり、ネイティブのカレンダーアプリに表示される「日付/時刻の選択」と同様のコントロールをエミュレートしようとしています。したがって、私のScrollViewerには、長方形とTextBlockを備えた複数の正方形のキャンバスを持つStackPanelが含まれています。私の意図は「ScrollStates」を監視することです。VisualStateが「NotScrolling」に変わったら、ScrollViewerのVerticalOffsetをチェックして、スライドを最も近い「スナップ先」の位置にアニメーション化します(つまり、正方形を正しい/中間の位置)。
<ScrollViewer Name="sv" Width="100" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled" Loaded="ScrollViewer_Loaded">
<StackPanel>
<Canvas MaxWidth="77" MaxHeight="80" MinWidth="80" MinHeight="80" Margin="3">
<Rectangle Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="3" Width="80" Height="80" />
<TextBlock Text="1" FontSize="36" FontWeight="Bold" TextAlignment="Center" HorizontalAlignment="Center" Width="70" Canvas.Left="6" Canvas.Top="14" LineHeight="48" />
</Canvas>
<Canvas MaxWidth="77" MaxHeight="80" MinWidth="80" MinHeight="80" Margin="3">
<Rectangle Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="3" Width="80" Height="80" />
<TextBlock Text="2" FontSize="36" FontWeight="Bold" TextAlignment="Center" HorizontalAlignment="Center" Width="70" Canvas.Left="6" Canvas.Top="14" LineHeight="48" />
</Canvas>
<Canvas MaxWidth="77" MaxHeight="80" MinWidth="80" MinHeight="80" Margin="3">
<Rectangle Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="3" Width="80" Height="80" />
<TextBlock Text="3" FontSize="36" FontWeight="Bold" TextAlignment="Center" HorizontalAlignment="Center" Width="70" Canvas.Left="6" Canvas.Top="14" LineHeight="48" />
</Canvas>
...
</StackPanel>
</ScrollViewer>
http://blogs.msdn.com/b/ptorr/archive/2010/07/23/how-to-detect-when-a-list-isのように、VisualStatesにフックするさまざまな例を見てきました。-scrolling-or-not.aspx ; http://developingfor.net/2009/02/16/fun-with-the-wpf-scrollviewer/ ; http://blogs.msdn.com/b/slmperf/archive/2011/06/30/windows-phone-mango-change-listbox-how-to-detect-compression-end-of-scroll-states.aspx。 ..すべてがこれに似たコードを持っているようです:
// Visual States are always on the first child of the control template
FrameworkElement element = VisualTreeHelper.GetChild(sv, 0) as FrameworkElement;
...次に、イベントを探し出しVisualStateGroup group = FindVisualState(element, "ScrollStates");
、そこからイベントが変更されたときにフックすることができます。
ただし、...を実行しようとするVisualTreeHelper.GetChild(sv,0) as FrameworkElement
と、「System.ArgumentOutOfRangeException」タイプの例外でアプリがクラッシュします。を出力VisualTreeHelper.GetChildrenCount(sv)
すると、常に「0」になります。それは他のすべての人にとってどのように機能しているように見えますか?8)
どんな助けでも大歓迎です。ありがとう!
(別の方法として、この種の「選択ボックス」を、再発明する代わりに使用できる再利用可能なコントロールにすでに作成した人はいますか?)