我为页面过渡效果制作了PageTransition UserControl,但是它不起作用。我不知道,为什么它不起作用。
我有DependencyProperty方面的经验,这是正确的工作。但是,我的新代码目前无法正常工作。
PageTransition.cs
public static readonly DependencyProperty CurrentViewProperty =
DependencyProperty.Register(nameof(CurrentView),
typeof(UserControl),
typeof(PageTransition));
public UserControl CurrentView
{
get => (UserControl)GetValue(CurrentViewProperty);
set
{
if(value is UserControl newControl)
{
Pages.Push(newControl);
if (CurrentView != default)
{
CurrentView.Loaded -= NewPageLoaded;
UnloadOldPage();
}
else
ShowNextPage();
}
}
}
PageTransition.cs.xaml
<ContentControl Content="{Binding CurrentView, Mode=TwoWay, ElementName=_this}" x:Name="contentControl">
</ContentControl>
MainWindow.cs
private UserControl currentPage = new MainPage() { DataContext = new MainPageViewModel() };
public UserControl CurrentPage
{
get => currentPage;
set
{
this.currentPage = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentPage)));
}
}
MainWindow.cs.xaml
<userControls:PageTransition
CurrentView="{Binding CurrentPage, ElementName=_this, Mode=TwoWay}"
TransitionType="SlideAndFade"/>
我正在MainWindow中使用PageTransition UserControl。当我在MainWindow中更改CurrentPage值时,PageTransition UserControl中的CurrentView值未更改