我正在使用的UWP应用有问题。基本上,该应用程序已完成,我想将其部署到Microsoft商店之外。
在Visual Studio 2017中运行时,应用程序运行良好,但是当我创建应用程序包并安装我的应用程序时,它只是打开空白页面而没有任何ui组件。应用程序不会抛出任何错误,它不会冻结。我可以调整空白窗口的大小,最小化,最大化和关闭。一切正常,除了没有按钮。
我尝试了什么
我尝试添加这行代码来更改正在运行的背景颜色。
(Application.Current.Resources [“ AppColorBackground”] as SolidColorBrush).Color = Colors.Crimson;
应用程序构造函数App()运行并更改背景颜色。
页面构造函数MyPage()运行并更改背景颜色。
页面方法OnNavigatedTo()运行并更改背景颜色。
MyTextBox.Text =“块中的新文本”;
查看MyTextBox是否存在。应用程序仍然不会引发错误,只是什么也没发生。
知道我尝试在Visual Studio中启动新的uwp项目,并逐步重写我的应用程序,并检查哪些代码行会导致问题。
一些其他信息。
我与Visual Studio community 2017(15.8.5版)合作
目标Windows版本1803内部版本17134
最低版本创建者更新了版本15063
我使用的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();
}
}
}
答案 0 :(得分:0)
我已找到造成问题的原因。遵循app.xmal中的代码行
<Style TargetType="Grid">
<Setter Property="Background" Value="{ThemeResource AppColorBackground}"/>
</Style>
这导致渲染UI出现奇怪的问题。部署后,整个网格将被背景色覆盖。