如何将Frame.Navigate设置为立即发生而不进行转换?

时间:2015-04-10 10:26:10

标签: windows-runtime windows-phone-8.1 win-universal-app

我正在使用Windows Phone 8.1应用程序作为Windows通用应用程序的一部分。按照Windows Universal Apps中extending splash screens的教程,我更改了我的App.xaml.cs以替换

if (!rootFrame.Navigate(typeof(SplashPage), e.Arguments))
{
    throw new Exception("Failed to create splash page");
}

if (e.PreviousExecutionState != ApplicationExecutionState.Running)
{
    var extendedSplash = new SplashPage(e.SplashScreen);
    Window.Current.Content = extendedSplash;
}

然而,这意味着当我覆盖Window.Current.Content时,我失去了对根框架的访问权限。我想改为使用

SplashPage.SplashScreen = e.SplashScreen;
if (!rootFrame.Navigate(typeof(SplashPage), e.Arguments))
{
    throw new Exception("Failed to create splash page");
}

但是现在页面已经过渡了。Frame.Navigate有一个覆盖,它需要额外的NavigationTransitionInfo参数,通常设置为其子类之一:

  1. CommonNavigationTransitionInfo(即从右侧滚入);
  2. SlideNavigationTransitionInfo(即向上滑动);或
  3. ContinuumNavigationTransitionInfo(即短暂放大)。
  4. (N.B.James Croft有一个很好的blog post显示这些过渡。)

    但是对于启动画面扩展,我需要立即显示页面,而不进行转换(就像通过使用新页面实例覆盖Window.Current.Content一样)。

    如何在没有转换的情况下立即设置Frame.Navigate

2 个答案:

答案 0 :(得分:2)

App中创建 rootFrame 之后,我会尝试通过将其设置为 null 来禁用默认 Frame.ContentTransitions .xaml.cs 文件(不要忘记处理不同的事件 - 启动/ ShareTarget / Activated - 如果需要):

rootFrame.ContentTransitions = null

一旦完成,页面就不应该进行转换。然后,如果需要,您可以在特定情况下为 Frame 的内容带回或设置新的过渡,或单独设置页面的过渡,例如在 Page 中XAML:

<Page.Transitions>
    <TransitionCollection>
        <EntranceThemeTransition/>
    </TransitionCollection>
</Page.Transitions>

答案 1 :(得分:0)

对于那些想对Windows 10 UWP应用执行相同操作的人,可以这样实现:

String filePath = "C:\\2018-02-28.json";
String filename = "2018-02-28.json";
File uploadedFile = new File("C:\\2018-02-28.json");
try {
   // HttpClient httpclient = HttpClientBuilder.create().build();
    String authHeader = authToken();
    HttpEntity entity = MultipartEntityBuilder
            .create()
            .addTextBody("name", "fileDate")
            .addTextBody("fileName", filename)
            .addTextBody("Content-Type", "application/json")
            .addBinaryBody("fileData", new File(filePath), ContentType.create("application/json"), filename)
            .build();

    HttpClient httpClient = HttpClients.custom()
            .setConnectionTimeToLive(2700, TimeUnit.SECONDS)
            .setMaxConnTotal(400).setMaxConnPerRoute(400)
            .setDefaultRequestConfig(RequestConfig.custom()
                    .setSocketTimeout(30000).setConnectTimeout(5000).build())
            .setRetryHandler(new DefaultHttpRequestRetryHandler(5, true))
            .build();

    HttpPost request = new HttpPost("http://md:8086/InputGateway/rest/input-gateway-service/ABC/invocations");
    request.setEntity(entity);
    request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
    HttpResponse resp = httpClient.execute(request);
    HttpEntity entity1 = resp.getEntity();
    System.out.println(EntityUtils.toString(entity1, "utf-8"));
    System.out.println("File has been Uploaded successfully: " + uploadedFile);
} catch (Exception ex) {
    throw new Exception( ex.toString());
}
}

根据this MSDN document