Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Xamarin Forms to create GTK Application with xaml Interface on UOS domestic system by dotnet

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how dotnet uses Xamarin Forms to create GTK applications with xaml interface on UOS domestic systems. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Here is how to build a GTK application through Xamarin.Forms using XAML to write interface logic on UOS domestic systems.

The editor will use a very low-level approach to tell you how to create it step by step, rather than how to create it quickly on IDE. Therefore, it is more suitable to tell you some basic content, but not suitable for large-scale creation.

Before you begin, please make sure that you have installed the environment and how to install it, please see the following blog

Dotnet installs MonoDevelop development tools on UOS domestic systems

Dotnet uses MonoDevelop to create GTK full-platform application with interface on UOS domestic system.

Dotnet uses MonoDevelop to drag controls on UOS home-made systems to develop GTK applications

As dotnet said in creating a full-platform GTK application with an interface using MonoDevelop on a domestic UOS system, create a blank GTK# application

Then create a console project, assuming that the project is Project A, the console project will add the Xamarin.Foms load, and then build the Xamarin.Forms-based interface dll file, and then by the GTK project, presumably named Project B, as the final native control support, mapped by Xamarin.Forms 's interface dll, so the new GTK project just created is the final entry project, and the application will be started by him.

Modify the csproj file to the following

Netstandard2.0

True

Portable

True

Some partners said that under Windows, it is also possible to create a new Xamarin.Forms project with VS and then copy it to UOS, but it should be noted that you cannot copy the bin and obj folders in the past, because there are many files in the obj folder that depend on the absolute path of the folder of the local computer. For example, the project.assests.json file in the nuget restore will contain the fallback path, if copied to the system under Linux. You may see the following hint

Error MSB4018 The "ResolvePackageAssets" >

Or

Error MSB4018 The "ResolvePackageAssets" task failed unexpectedly. NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder'C:\ Program Files (x86)\ Xamarin\ NuGet\'

If you forget this and copy the obj folder, you can delete the obj folder under the Linux system UOS to solve the problem that Xamarin Forms failed to build in the Linux system.

Ignoring the method of creating Xamarin Forms from systems such as Windows, let's create it step by step on UOS

Delete the Program.cs file for project A, that is, the console project where Xamarin Forms is installed

Then choose to create a new empty xml file, modify it and name it App.xaml file after creation, and create an empty class called App.xaml.cs file.

These two files will represent the start of the Xamarin Forms project, that is, at the startup entry of the Xamarin layer. In GTK applications using Xamarin.Forms, there are two levels of entrances. The first layer is the entrance to the native program, that is, the Main method entry for the Program file of Project B, and the second layer is the App entry for Xamarin.Forms. When the application starts, enter the first-tier entrance, initialize the native-related processes at the first-tier entrance, and then enter the second-tier entrance to initialize the Xamarin application at the second-tier entrance

Add the following code to App.xaml, and the following code's xWokemhelurnawgelrallKearlallidallla Class = "WokemhelurnawgelrallKearlallidallla.App" is actually the project name.

In fact, the above App.xaml is empty code, meaningful code is put in the App.xaml.cs, please see the code

Using Xamarin.Forms

Namespace WokemhelurnawgelrallKearlallidallla

{

Public partial class App: Application

{

Public App ()

{

InitializeComponent ()

MainPage = new MainPage ()

}

}

}

The core of the above code is to call the InitializeComponent method in the constructor, and then set the main page

Then we need to create a new main interface, create a new xml file for MainPage, and then modify it and name it MainPage.xaml.

Then fill in the interface code

Please don't change too much content yet, ha.

Then create a new MainPage.xaml.cs file and add the following code

Using System.ComponentModel

Using Xamarin.Forms

Namespace WokemhelurnawgelrallKearlallidallla

{

[DesignTimeVisible (false)]

Public partial class MainPage: ContentPage

{

Public MainPage ()

{

InitializeComponent ()

}

}

}

Now you have a new App application and an interface for MainPage, but you also need an AssemblyInfo.cs file to set the assembly properties.

Using Xamarin.Forms.Xaml

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]

Such a simple Xamarin Forms project is complete. Set up the GTK project, that is, Project B, and reference the Xamarin Forms project, that is, Project A.

But at this point you will find that the build failed because Project B, the GTK project, did not reference enough NuGet packages. Add the following NuGet libraries to Project B

OpenTK

Xamarin.Forms

Xamarin.Forms.Platform.GTK

Then open the Program.cs file of Project B and add the following code to the Main method

Gtk.Application.Init ()

Forms.Init ()

Var app = new App ()

Var window = new FormsWindow ()

Window.LoadApplication (app)

Window.SetApplicationTitle ("lindexi")

Window.Show ()

Gtk.Application.Run ()

Pay attention to adding using references in the editor

Then delete other cs code files except Program.cs

At this point in Project B, after building, you can see the following interface

This is the end of the GTK application about how dotnet uses Xamarin Forms to create xaml interface on UOS domestic system. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report