У меня проблема с переходами в данный момент с использованием http://www.codeproject.com/KB/WPF/WpfPageTransitions.aspx
Проблема в том, что если у меня есть кнопка на UserControl1
и когда кнопка нажата, она вызывает UserControl2
для перехода,но когда это происходит, фон UserControl2
виден, но другие элементы, такие как текст и кнопки, объединяются вместе с UserControl1
.
. Как можно применить переход к UserControl1
, чтобы только UserControl2
отображается?
Модифицированный код:
NewPage.xml
private void button1_Click(object sender, RoutedEventArgs e)
{
Test test = new Test();
pageTransitionControl.SetPreviousUserControl(newPage);
pageTransitionControl.ShowPage(test);
}
PageTransition.xaml.cs
public partial class PageTransition : UserControl
{
private UserControl currentUserControl;
private UserControl previousUserControl;
public static readonly DependencyProperty TransitionTypeProperty = DependencyProperty.Register("TransitionType",
typeof(PageTransitionType),
typeof(PageTransition), new PropertyMetadata(PageTransitionType.SlideAndFade));
public PageTransitionType TransitionType
{
get
{
return (PageTransitionType)GetValue(TransitionTypeProperty);
}
set
{
SetValue(TransitionTypeProperty, value);
}
}
public PageTransition()
{
InitializeComponent();
}
public void ShowPage(UserControl newPage)
{
currentUserControl = newPage;
if (contentPresenter.Content != null)
{
UserControl oldPage = contentPresenter.Content as UserControl;
oldPage.Loaded -= newPage_Loaded;
UnloadPage(oldPage);
}
else
{
ShowNextPage();
}
}
void ShowNextPage()
{
currentUserControl.Loaded += newPage_Loaded;
contentPresenter.Content = currentUserControl;
if (currentUserControl != null)
{
currentUserControl.Visibility = Visibility.Visible;
Panel.SetZIndex(currentUserControl, 100);
}
if (previousUserControl != null)
{
previousUserControl.Visibility = Visibility.Visible;
Panel.SetZIndex(previousUserControl, 0);
}
}
void UnloadPage(UserControl page)
{
Storyboard hidePage = (Resources[string.Format("{0}Out", TransitionType.ToString())] as Storyboard).Clone();
hidePage.Completed += hidePage_Completed;
hidePage.Begin(contentPresenter);
}
void newPage_Loaded(object sender, RoutedEventArgs e)
{
Storyboard showNewPage = Resources[string.Format("{0}In", TransitionType.ToString())] as Storyboard;
showNewPage.Begin(contentPresenter);
currentUserControl = sender as UserControl;
}
void hidePage_Completed(object sender, EventArgs e)
{
contentPresenter.Content = null;
ShowNextPage();
}
public void SetPreviousUserControl(UserControl userControl)
{
previousUserControl = userControl;
}
}