gpt4 book ai didi

c# - 导航转换 - Windows Phone 工具包

转载 作者:行者123 更新时间:2023-11-30 19:25:56 25 4
gpt4 key购买 nike

我正在开发一个 Windows Phone 8.1 silverlight 应用程序,我想在我的页面之间提供简单的导航转换。

我在 Nuget 上找到了 Windows Phone 工具包。不幸的是,过渡服务的导航过渡不起作用。我究竟做错了什么? (我使用 Caliburn Micro 作为 mvvm 框架)

Bootstrapper.cs

public sealed class Bootstrapper : PhoneBootstrapperBase
{
public PhoneContainer Container { get; set; }

public Bootstrapper()
{
StartRuntime();
}

protected override void Configure()
{

Container = new PhoneContainer();

Container.RegisterPhoneServices(RootFrame);
Container.Singleton<MainViewModel>()

AddCustomConventions();
}

static void AddCustomConventions()
{
//ellided
}

protected override object GetInstance(Type service, string key)
{
return Container.GetInstance(service, key);
}

protected override IEnumerable<object> GetAllInstances(Type service)
{
return Container.GetAllInstances(service);
}

protected override void BuildUp(object instance)
{
Container.BuildUp(instance);
}

protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
{
return new TransitionFrame();
}


}

MainView.xaml

...
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
...

<Grid x:Name="LayoutRoot">
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition>
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardOut"/>
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardOut"/>
</toolkit:NavigationOutTransition.Forward>
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

...

</Grid>

App.xaml.cs

public sealed partial class App : Application
{
public static PhoneApplicationFrame RootFrame { get; private set; }

public App()
{
InitializeComponent();

if (!Debugger.IsAttached) return;
Application.Current.Host.Settings.EnableFrameRateCounter = false;

PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;

}
}

或者,在 Windows Phone SL 8.1 应用程序中提供导航转换的其他方法是什么?

最佳答案

这是我的做法(从各种来源拼凑而成,我现在不太记得了):

  1. 创建一个名为 Transitions 之类的带有过渡的类(您不必添加所有过渡,只需添加您需要的):

    //Turnstile transition
    public static void UseTurnstileTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new TurnstileTransition()
    {
    Mode = TurnstileTransitionMode.BackwardIn
    },
    Forward = new TurnstileTransition()
    {
    Mode = TurnstileTransitionMode.ForwardIn
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new TurnstileTransition()
    {
    Mode = TurnstileTransitionMode.BackwardOut
    },
    Forward = new TurnstileTransition()
    {
    Mode = TurnstileTransitionMode.ForwardOut
    }
    }
    );
    }

    //Slide transition
    public static void UseSlideTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideRightFadeIn
    },
    Forward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideLeftFadeIn
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideRightFadeOut
    },
    Forward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideLeftFadeOut
    }
    }
    );
    }

    //Slide up/down transition
    public static void UseSlideUpDownTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideUpFadeIn
    },
    Forward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideDownFadeIn
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideUpFadeOut
    },
    Forward = new SlideTransition()
    {
    Mode = SlideTransitionMode.SlideDownFadeOut
    }
    }
    );
    }

    //Swivel transition
    public static void UseSwivelTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new SwivelTransition()
    {
    Mode = SwivelTransitionMode.BackwardIn
    },
    Forward = new SwivelTransition()
    {
    Mode = SwivelTransitionMode.ForwardIn
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new SwivelTransition()
    {
    Mode = SwivelTransitionMode.BackwardOut
    },
    Forward = new SwivelTransition()
    {
    Mode = SwivelTransitionMode.ForwardOut
    }
    }
    );
    }

    //Rotate transition
    public static void UseRotateTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new RotateTransition()
    {
    Mode = RotateTransitionMode.In90Clockwise
    },
    Forward = new RotateTransition()
    {
    Mode = RotateTransitionMode.In180Clockwise
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new RotateTransition()
    {
    Mode = RotateTransitionMode.Out180Counterclockwise
    },
    Forward = new RotateTransition()
    {
    Mode = RotateTransitionMode.Out90Counterclockwise
    }
    }
    );
    }

    //Roll transition (doesn't have any modes)
    public static void UseRollTransition(UIElement element)
    {
    TransitionService.SetNavigationInTransition(element,
    new NavigationInTransition()
    {
    Backward = new RollTransition()
    {
    //Mode = RollTransitionMode.In90Clockwise
    },
    Forward = new RollTransition()
    {
    //Mode = RollTransitionMode.In180Clockwise
    }
    }
    );

    TransitionService.SetNavigationOutTransition(element,
    new NavigationOutTransition()
    {
    Backward = new RotateTransition()
    {
    //Mode = RotateTransitionMode.Out180Counterclockwise
    },
    Forward = new RotateTransition()
    {
    //Mode = RotateTransitionMode.Out90Counterclockwise
    }
    }
    );
    }

2) 在所有要应用转换的页面的页面构造函数中添加要使用的转换:

public MainPage()
{
InitializeComponent();

this.Loaded += new RoutedEventHandler(MainPage_Loaded);

//Setup page transitions using custom class file
//1. Turnstile transition
Transitions.UseTurnstileTransition(this);
//2. Slide transition
//Transitions.UseSlideTransition(this);
//3. Slide up/down transition
//Transitions.UseSlideUpDownTransition(this);
//4. Swivel transition
//Transitions.UseSwivelTransition(this);
//5. Rotate transition
//Transitions.UseRotateTransition(this);
//6. Roll transition
//Transitions.UseRollTransition(this);
}

3) 最后,您需要将 App.xaml.cs 中的 RootFrame 从 PhoneApplicationFrame 更改为 TransitionFrame:

//RootFrame = new PhoneApplicationFrame();
RootFrame = new TransitionFrame();

在那之后,您的正常页面转换应该更改为您在页面构造器中选择的任何一个 - 通过将它们全部注释在那里,您可以尝试不同的。刚刚在一个空白的应用程序中进行了尝试,它成功了 - 希望它能有所帮助。

关于c# - 导航转换 - Windows Phone 工具包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26089007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com