코드 슬라이딩 패널 - 프로그램에서 SelectedIndex 설정
5870 단어 select
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[newIndex]);
프로그램을 통해 SelectedItem을 변경할 수 있지만 panorama는 바로 업데이트되지 않습니다. 코드는 다음과 같습니다.
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]);
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;
Item , , item , RenderTransform , target RenderTransform。
:
private void slidePanorama(Panorama pan)
{
FrameworkElement panWrapper = VisualTreeHelper.GetChild(pan, 0) as FrameworkElement;
FrameworkElement panTitle = VisualTreeHelper.GetChild(panWrapper, 1) as FrameworkElement;
//Get the panorama layer to calculate all panorama items size
FrameworkElement panLayer = VisualTreeHelper.GetChild(panWrapper, 2) as FrameworkElement;
//Get the title presenter to calculate the title size
FrameworkElement panTitlePresenter = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(panTitle, 0) as FrameworkElement, 1) as FrameworkElement;
//Current panorama item index
int curIndex = pan.SelectedIndex;
//Get the next of next panorama item
FrameworkElement third = VisualTreeHelper.GetChild(pan.Items[(curIndex + 2) % pan.Items.Count] as PanoramaItem, 0) as FrameworkElement;
//Be sure the RenderTransform is TranslateTransform
if (!(pan.RenderTransform is TranslateTransform)
|| !(panTitle.RenderTransform is TranslateTransform))
{
pan.RenderTransform = new TranslateTransform();
panTitle.RenderTransform = new TranslateTransform();
}
//Increase width of panorama to let it render the next slide (if not, default panorama is 480px and the null area appear if we transform it)
pan.Width = 960;
//Animate panorama control to the right
Storyboard sb = new Storyboard();
DoubleAnimation a = new DoubleAnimation();
a.From = 0;
a.To = -(pan.Items[curIndex] as PanoramaItem).ActualWidth; //Animate the x transform to a width of one item
a.Duration = new Duration(TimeSpan.FromMilliseconds(700));
a.EasingFunction = new CircleEase(); //This is default panorama easing effect
sb.Children.Add(a);
Storyboard.SetTarget(a, pan.RenderTransform);
Storyboard.SetTargetProperty(a, new PropertyPath(TranslateTransform.XProperty));
//Animate panorama title separately
DoubleAnimation aTitle = new DoubleAnimation();
aTitle.From = 0;
aTitle.To = (panLayer.ActualWidth - panTitlePresenter.ActualWidth) / (pan.Items.Count - 1) * 1.5; //Calculate where should the title animate to
aTitle.Duration = a.Duration;
aTitle.EasingFunction = a.EasingFunction; //This is default panorama easing effect
sb.Children.Add(aTitle);
Storyboard.SetTarget(aTitle, panTitle.RenderTransform);
Storyboard.SetTargetProperty(aTitle, new PropertyPath(TranslateTransform.XProperty));
//Start the effect
sb.Begin();
//After effect completed, we change the selected item
a.Completed += (obj, args) =>
{
//Reset panorama width
pan.Width = 480;
//Change the selected item
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]);
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;
//Reset panorama render transform
(pan.RenderTransform as TranslateTransform).X = 0;
//Reset title render transform
(panTitle.RenderTransform as TranslateTransform).X = 0;
//Because of the next of next item will be load after we change the selected index to next item
//I do not want it appear immediately without any effect, so I create a custom effect for it
if (!(third.RenderTransform is TranslateTransform))
{
third.RenderTransform = new TranslateTransform();
}
Storyboard sb2 = new Storyboard();
DoubleAnimation aThird = new DoubleAnimation() { From = 100, To = 0, Duration = new Duration(TimeSpan.FromMilliseconds(300)) };
sb2.Children.Add(aThird);
Storyboard.SetTarget(aThird, third.RenderTransform);
Storyboard.SetTargetProperty(aThird, new PropertyPath(TranslateTransform.XProperty));
sb2.Begin();
};
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
🕗[프로그래머스] 입양 시각 구하기(2)문제 설명 ANIMAL_OUTS 테이블은 동물 보호소에서 입양 보낸 동물의 정보를 담은 테이블입니다. ANIMAL_OUTS 테이블 구조는 다음과 같으며, ANIMAL_ID, ANIMAL_TYPE, DATETIME, ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.