Launch Xamarin.Forms on Windows 7
Xamarin.Forms is quite an interesting and promising framework, which is now actively developing and allows you to quickly get a cross-platform application. By default, Xamarin.Forms supports 5 platforms, namely: Android, iOS, WP, WinRT, UWP.
Despite the fact that Microsoft is trying to actively transfer its users to Windows 10, today Windows 7 is still very common in many organizations, and there is a need to port / develop an application for Windows 7.
I had the same situation - we had to develop The solution is not only for Android and iOS, but also for Windows 7.
Fortunately, Microsoft opened the source code for Xamarin.Forms, and as an experiment, especially not hoping for anything, I forked Xamarin.Forms and ported the Xamarin.Forms.WP solution to WPF.
What came out of this can be seen below with simple examples.
Let's start with a simple form:
By default, WPF looks as if the application was created in the native XAML WPF:
For comparison, Win8:
and iOS (iPad):
Now let's take something more complicated - an example of generating a page with a chessboard from the code of the book Xamarin.Forms )
Running this code on WPF, iOS (iPhone), WP, we get the following picture:
You can download the project source code and connect with github .
However, if you don’t want to mess with the source code and just want to connect and test the performance of your project with WPF, you can download ready-made assemblies from the link .
Instructions for connecting:
1. Add a new project with WPF Application to your solution with Xamarin.Forms.
2. Add links to the downloaded DLLs to the new project.
3. Add a link to the main project with Xamarin.Forms code (for example, the name of the project is MyProgramm.Core).
4. Replace the MainWindow class (in the MainWindow.xaml.cs file) with the following code:
Please note: It is important not to confuse the App class from WPF and the App class from Xamarin.Forms
5. In MainWindow.xaml, change the root element from Window to FormsApplicationPage.
Note: the namespace xmlns: local = "clr-namespace: MyProgramm.WPF".
That's all, you can try to run your application!
At the moment, the project is in a very raw state, and first of all, attention will be paid to those shortcomings and bugs that will be needed at my main job.
Initially, the project was created at home as an experiment. At the moment, we are actively using it, we are finalizing it at work, and since I spent a lot of working time on finalizing the project, we plan to move to the company's official Github with the creation of the minimum necessary documentation and project templates for installation.
When the project is in a fairly stable state and the most critical bugs are closed, we will most likely return the fork to the official repository.
At the moment, the Xamarin.Forms.WPF project looks quite promising for us and already now allows us to save the efforts of our developers on the lack of duplication of code with all the ensuing consequences separately for WPF. In the future, there is a desire to try strength in the direction of Xamarin.Forms.Mac. There is a much more difficult idea with Xamarin.Forms.Web plans.
If the project aroused interest, I invite you to join the project and take part in the development of the product.
Despite the fact that Microsoft is trying to actively transfer its users to Windows 10, today Windows 7 is still very common in many organizations, and there is a need to port / develop an application for Windows 7.
I had the same situation - we had to develop The solution is not only for Android and iOS, but also for Windows 7.
Fortunately, Microsoft opened the source code for Xamarin.Forms, and as an experiment, especially not hoping for anything, I forked Xamarin.Forms and ported the Xamarin.Forms.WP solution to WPF.
What came out of this can be seen below with simple examples.
Demo
Let's start with a simple form:
By default, WPF looks as if the application was created in the native XAML WPF:
For comparison, Win8:
and iOS (iPad):
Now let's take something more complicated - an example of generating a page with a chessboard from the code of the book Xamarin.Forms )
public class ChessboardFixedPage : ContentPage
{
public ChessboardFixedPage()
{
const double squareSize = 35;
AbsoluteLayout absoluteLayout = new AbsoluteLayout
{
BackgroundColor = Color.FromRgb(240, 220, 130),
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
for (int row = 0; row < 8; row++)
{
for (int col = 0; col < 8; col++)
{
// Skip every other square.
if (((row ^ col) & 1) == 0)
continue;
BoxView boxView = new BoxView
{
Color = Color.FromRgb(0, 64, 0)
};
Rectangle rect = new Rectangle(col * squareSize,
row * squareSize,
squareSize, squareSize);
absoluteLayout.Children.Add(boxView, rect);
}
}
this.Content = absoluteLayout;
}
}
Running this code on WPF, iOS (iPhone), WP, we get the following picture:
How to connect
You can download the project source code and connect with github .
However, if you don’t want to mess with the source code and just want to connect and test the performance of your project with WPF, you can download ready-made assemblies from the link .
Instructions for connecting:
1. Add a new project with WPF Application to your solution with Xamarin.Forms.
2. Add links to the downloaded DLLs to the new project.
3. Add a link to the main project with Xamarin.Forms code (for example, the name of the project is MyProgramm.Core).
4. Replace the MainWindow class (in the MainWindow.xaml.cs file) with the following code:
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Forms.Init();
var app = new MyProgramm.Core.App();
LoadApplication(app);
}
}
Please note: It is important not to confuse the App class from WPF and the App class from Xamarin.Forms
5. In MainWindow.xaml, change the root element from Window to FormsApplicationPage.
Note: the namespace xmlns: local = "clr-namespace: MyProgramm.WPF".
That's all, you can try to run your application!
condition
At the moment, the project is in a very raw state, and first of all, attention will be paid to those shortcomings and bugs that will be needed at my main job.
Development
Initially, the project was created at home as an experiment. At the moment, we are actively using it, we are finalizing it at work, and since I spent a lot of working time on finalizing the project, we plan to move to the company's official Github with the creation of the minimum necessary documentation and project templates for installation.
When the project is in a fairly stable state and the most critical bugs are closed, we will most likely return the fork to the official repository.
Summary
At the moment, the Xamarin.Forms.WPF project looks quite promising for us and already now allows us to save the efforts of our developers on the lack of duplication of code with all the ensuing consequences separately for WPF. In the future, there is a desire to try strength in the direction of Xamarin.Forms.Mac. There is a much more difficult idea with Xamarin.Forms.Web plans.
If the project aroused interest, I invite you to join the project and take part in the development of the product.