WP7でScrollviewerを作成しました.3つのusercontrolがあり、それぞれがコンテンツとしてXAMLが作成したUserControlを保持しています。これは正常に動作します。このスクロールビューアはこれらの項目間をスクロールできる必要がありますが、ユーザーがスクロールすることはできません。したがって、これらのコンテンツのいずれかのアイテムがクリックされると、スクロールビューアは選択されたアイテムに応じて左右にスライドし、他のユーザコントロールの1つを表示します。私はこれを達成するために仲介者を使用します。基本的にはscrollbarvisibilityがdisabledに設定されていると、Scrollviewerがスクロールバックしないようにするにはどうすればよいですか? wp7
<Grid.Resources>
<Storyboard x:Name="ItemAnimation">
<DoubleAnimation x:Name="ItemAnimationContent"
Storyboard.TargetName="Mediator"
Storyboard.TargetProperty="ScrollableWidthMultiplier"/>
</Storyboard>
</Grid.Resources>
<ScrollViewer Name="ScrollableItemPanel"
Grid.Row="2"
Grid.RowSpan="3"
Grid.ColumnSpan="3"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal">
<UserControl Name="NewsListBoxControl" Width="480" />
<UserControl Name="DetailedItemControl" Width="480"/>
<UserControl Name="ExternalBrowserItemControl" Width="480"/>
</StackPanel>
</ScrollViewer>
<local:ScrollableItemAnimationMediator x:Name="Mediator"
ScrollViewer="{Binding ElementName=ScrollableItemPanel}"/>
を、これはあまりにも正常に動作し、私は項目間を移動し、それらにユーザーコントロールなどのコンテンツを読み込むことができます。しかし、問題は、ユーザーにスクロールする能力を与えることにあります。アイテムをスクロールする前に、hittestvisibiltyをtrueに設定し、horizontalcrollbarvisibilityをvisibleに設定します。アニメーションが終了したら、ヒット・ティスビジビリティを戻して、horizontalcrollbarvisibilityを再びDisabledに設定します。これは後者の問題です:horizontalscrollbarvisibilityをDisabledに設定すると、スクロールビューアは自動的にスタックパネルの3つの項目の最初の部分を表示します。どうすればこれをやめることができますか? 、私はすでに、その後、この質問を答えとして、私はそれはすなわちScrollbarVisibility.Hidden代わりのScrollbarVisibility.Disabledを使用して、答えられると考えて、それを考えていた
private void CreateDetailedArticleItem(Dictionary<string, string> itemQuery)
{
_articleDetailPage.ItemQuery = itemQuery;
DetailedItemControl.Content = _articleDetailPage as UserControl;
Animate(_articleDetailPage, 0.0f, 0.5f, 250);
}
private void Animate(IContentControl control, float from, float to, double milliseconds)
{
//this eventhandler will fire when the animation has completed
EventHandler handler = null;
//we take away the User Input just for the moment, so that we can animate without the user interfering. Also, we make horizontalScroll Visible
IsUserEnabled = false;
//we then set the content of the animation. Where from will it move, towards where and in what duration?
ItemAnimationContent.From = from;
ItemAnimationContent.To = to;
ItemAnimationContent.Duration = TimeSpan.FromMilliseconds(milliseconds);
//we start the animation
ItemAnimation.Begin();
//we tell the new control that it will appear soon, so it can load its main content
control.ViewWillAppear();
//also, we tell the currentcontrol that it will disappear soon, so it can unload its content and eventhandlers and so on
CurrentControl.ViewWillDisAppear();
//the handler is a delegate. This way, it becomes rather easy and clean to fire the completed event, without creating a strong reference (well, actually,
//we do create a strong reference, but as soon as it is fired, we remove it again, shhhh!).
handler = delegate(object sender, EventArgs e)
{
//as stated, we remove the eventlistener again, so it won't keep firing all the time
ItemAnimation.Completed -= handler;
//after the animation, we tell the new control that it is now in screen, and can start downloading its data
control.ViewDidAppear();
//at the same time, the "current" control has fully moved out of view, so it can now fully unload all its content.
CurrentControl.ViewDidDisAppear();
//now, all we have to do is to make sure that the next time an item is being loaded, the new content is spoken to, not the old one
CurrentControl = control;
//and finally, enable the users input again, and remove the horizontal scrollbarvisibility
IsUserEnabled = true;
};
ItemAnimation.Completed += handler;
}
private bool IsUserEnabled
{
set
{
//when the user can control the scrollviewer, then the horizontal scrollvisibility is disabled, so that the user cannot move horizontally,
//otherwise, so we only make it visible when the program needs to animate.
ScrollableItemPanel.IsHitTestVisible = value;
ScrollableItemPanel.HorizontalScrollBarVisibility = value ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Visible;
}
}
:これは私が仲介者をスクロールするために使用するコードですスクロールバービビリティのみがこのように表示され、ユーザーはスクロールできます。この問題に対処するネイティブな方法はありますか?
ご協力いただければ幸いです。 Greetz
ええ、私は実際には(答えを待っている間に他のものに取り組んでいる)と思っていましたが、ネイティブが存在するかもしれないと思っていました。 あなたが知っている限り、スクロールビューアのこの欠陥を回避する方法はありません、私はそれを取る? – GeekPeek
それは間違いなくコントロールの欠陥ではありません。あなたはそれが設計されていないもののためにそれを使用しようとしています。 –
ええ、それは本当です、私はそれが奇妙に思えるのは、Scrollbarvisibilityが可視性を隠す2つの方法を提供しています。その1つはスクロールを妨げません(私はそれが単に表示スクロールバーを隠すと思います)。すぐにそれを不可視に設定してから とにかく、私は今あなたが提案した方法で作業しています。ありがとう= 3 – GeekPeek