Как показано ниже, я заметил, что когда вы создаете проект UWP
в VS2019
, он создает конструктор public App(){....}
в классе приложения App.xaml.cs
проекта. Затем этот конструктор можно использовать для вызова (например) методов проекта .NET Standard Class Library в том же решении, как показано во втором блоке кода здесь .
Но, как показано ниже, класс приложения App.xaml.cs
проекта WPF
не имеет такого конструктора, созданного по умолчанию.
Вопрос Можно ли просто создать конструктор вручную public App(){....}
в классе приложения App.xaml.cs
проекта WPF
и вызовите оттуда метод стандартной библиотеки классов .NET, или это может вызвать проблемы позже?
App.xaml.cs
проекта UWP
:
using System;
using System.IO;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
......
namespace Test_UWP_Project
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
..........
............
}
Проект App.xaml.cs
из WPF
:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Windows;
.....
.....
namespace Test_WPF_Project
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}