简体   繁体   English

UWP App部署后不会创建UI元素

[英]UWP App does not create UI elements after deploy

I have a problem with an UWP app that I am working on. 我正在处理的UWP应用有问题。 Basically the app is finished and I want to deploy it outside the Microsoft store. 基本上,该应用程序已完成,我想将其部署到Microsoft商店之外。

App working fine when run within visual studio 2017 but when I create app package and install my app, it just open blank page without any ui components. 在Visual Studio 2017中运行时,应用程序运行良好,但是当我创建应用程序包并安装我的应用程序时,它只是打开空白页面而没有任何ui组件。 App do not throw any error it do not freez. 应用程序不会抛出任何错误,它不会冻结。 I can resize my blank window, minimalize, maximize and close. 我可以调整空白窗口的大小,最小化,最大化和关闭。 Everything act normal except there is no buttons. 一切正常,除了没有按钮。

What have I try: 我尝试了什么:

  1. I have change my mine page to different one to check if this error occur for one page or in whole app. 我已将我的地雷页面更改为另一页面,以检查此错误是发生在一页还是整个应用程序中。 No mater which page is main it is always empty. 没有资料显示哪个页面是主要页面,它始终为空。
  2. I have created new empty page and added simple TextBlock and set it as mine page for app but still it open without this textblock. 我创建了一个新的空白页面,并添加了简单的TextBlock并将其设置为应用程序的我的页面,但仍然打开时没有此文本块。
  3. I try which part of code is running by adding this line of code which will change app background color. 我通过添加以下代码行来尝试运行代码的哪一部分,这将更改应用程序的背景色。

    (Application.Current.Resources["AppColorBackground"] as SolidColorBrush).Color = Colors.Crimson; (Application.Current.Resources [“ AppColorBackground”]为SolidColorBrush)。Color= Colors.Crimson;

Application constructor App() runs and change background color. 应用程序构造函数App()运行并更改背景色。

Page constructor MyPage() runs and change background color. 页面构造函数MyPage()运行并更改背景颜色。

Page method OnNavigatedTo() runs and change background color. 页面方法OnNavigatedTo()运行并更改背景颜色。

  1. I thought that InitializateComponent() method do not run and do not crate ui componets. 我认为InitializateComponent()方法不会运行,也不会创建ui组件。 After initializateComponent() method I added following line of code 在initializateComponent()方法之后,我添加了以下代码行

MyTextBox.Text = "New text in block"; MyTextBox.Text =“块中的新文本”;

To see if MyTextBox exist. 查看MyTextBox是否存在。 App still do not throw error, simply nothing happen. 应用程序仍然不会引发错误,只是什么也没有发生。

  1. Asked my friends if some have similar problem. 问我的朋友是否有类似的问题。
  2. Asked google 问谷歌
  3. And now I ask you stackoverflow community have you encountered similar problem? 现在我问你stackoverflow社区,你遇到过类似的问题吗?

Know I try to start new uwp project in visual studio and rewrite my app step by step and check what line of code will cause the problem. 知道我尝试在Visual Studio中启动新的uwp项目,并逐步重写我的应用程序,并检查哪些代码行会引起问题。

Some additional info. 一些其他信息。

I work with Visual Studio community 2017 (ver.15.8.5) 我使用Visual Studio社区2017(版本15.8.5)

Targeted windows version 1803 build 17134 目标Windows版本1803内部版本17134

Min version creators update build 15063 最低版本创建者更新版本15063

Nuget package that I use: SignalR client, Newtonsoft Json, Telerik UI for UWP 我使用的Nuget软件包:SignalR客户端,Newtonsoft Json,用于UWP的Telerik UI

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using NaviParkManager.Controller;
using NaviParkManager.Model;
using NaviParkManager.Pages;

namespace NaviParkManager
{
    sealed partial class App : Application
    {
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            ApplicationView.PreferredLaunchViewSize = new Size(960, 540);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
            localSettings.Values["launchedWithPrefSize"] = true;
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
        }

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // TitleBar config
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            var titleBar = ApplicationView.GetForCurrentView().TitleBar;
            titleBar.ButtonBackgroundColor = Colors.Transparent;
            titleBar.ButtonForegroundColor = ((SolidColorBrush)Application.Current.Resources["AppColorText"]).Color;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(TestPage), e.Arguments);
                    //rootFrame.Navigate(typeof(UserLogInPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }

        void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
        }

        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Save application state and stop any background activity
            deferral.Complete();
        }


    }
}

I have found cause of my problem. 我发现了问题的原因。 Following line of code in app.xmal 跟随app.xmal中的代码行

<Style TargetType="Grid">
    <Setter Property="Background" Value="{ThemeResource AppColorBackground}"/>
</Style>

It caused weird issue with rendering UI. 导致渲染UI出现奇怪问题。 After deploy whole grid is cover by background color. 部署后,整个网格被背景色覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM