Skip to content

Commit 311329f

Browse files
authored
Merge pull request #11134 from unoplatform/mergify/bp/release/stable/4.7/pr-11085
fix(template): Move app.xaml.cs to shared "AppBase" (backport #11085)
2 parents bbfcac4 + 1e05314 commit 311329f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+322
-79
lines changed
43.3 KB
Loading
Loading

doc/articles/Uno-UI-Performance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Here's what to look for:
7878
```
7979
- Resources
8080
- Avoid using `x:Name` in `ResourceDictionary` as those force early instantiation of the resource
81-
- Use [`Uno.XamlMerge.Task`](https://github.com/unoplatform/uno.xamlmerge.task) to merge all top-level App.xaml resource dictionaries
81+
- Use [`Uno.XamlMerge.Task`](https://github.com/unoplatform/uno.xamlmerge.task) to merge all top-level `AppResources.xaml` or `App.xaml` resource dictionaries
8282

8383
## WebAssembly specifics
8484
- Building your application in Release configuration is critical to get the best performance.

doc/articles/controls/ComboBox.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ On Uno you can change this behavior.
1313

1414
### Change the default value for all the `ComboBox` in you application
1515

16-
The default placement for all `ComboBox` instances can be changed by setting the feature flag in the startup of your app (app.xaml.cs) :
16+
The default placement for all `ComboBox` instances can be changed by setting the feature flag in the startup of your app (`app.cs` or `app.xaml.cs`) :
1717

1818
```cs
1919
Uno.UI.FeatureConfiguration.ComboBox.DefaultDropDownPreferredPlacement = DropDownPlacement.Below;

doc/articles/controls/TimePicker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you wish to customize the overlay color, add the following to your top-level
5656
Color="Pink" />
5757
```
5858

59-
Since **iOS14** the native `TimePicker` changed the way it's presented. By default iOS14 devices will display this new style. You can still force the previous style (the one found in iOS13 or earlier) by adding the following at your `App.xaml.cs` class:
59+
Since **iOS14** the native `TimePicker` changed the way it's presented. By default iOS14 devices will display this new style. You can still force the previous style (the one found in iOS13 or earlier) by adding the following at your `App.cs` or `App.xaml.cs` class:
6060

6161
```csharp
6262
Uno.UI.FeatureConfiguration.TimePicker.UseLegacyStyle = true;

doc/articles/controls/map-control-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The current implementation uses the native UIKit Map for iOS and the Google Play
1212

1313
1. Ensure your app is targeting Uno 3.3 or later.
1414
2. Install the [Uno.UI.Maps NuGet package](https://www.nuget.org/packages/Uno.UI.Maps/) in the Android and/or iOS head projects of your app.
15-
3. Add the `MapResources` resource dictionary to `Application.Resources` in your `App.xaml` file:
15+
3. Add the `MapResources` resource dictionary to `Application.Resources` in your `AppResources.xaml` or `App.xaml` file:
1616
```xml
1717
<Application.Resources>
1818
<MapResources xmlns="using:Uno.UI.Maps"/>

doc/articles/features/fluent-styles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Uno Platform 3.0 and above supports control styles conforming to the [Fluent des
44

55
## Upgrading existing Uno apps to use Fluent styles
66

7-
Overall, the Uno Platform uses the same mechanism as WinUI to enable Fluent styles. After installing the `Uno.UI` Nuget version 3.0 or above, Fluent styles are enabled by specifying the `XamlControlsResources` within the application's resources (inside `App.xaml`).
7+
Overall, the Uno Platform uses the same mechanism as WinUI to enable Fluent styles. After installing the `Uno.UI` Nuget version 3.0 or above, Fluent styles are enabled by specifying the `XamlControlsResources` within the application's resources (inside `AppResources.xaml` or `App.xaml`).
88

99
For the UWP head, an additional WinUI 2 Nuget package reference must be added. This is following the same process as UWP because, for the UWP head, the Uno Platform is not used.
1010

1111
The step-by-step process to enable Fluent design styles within an existing Uno Platform solution is as follows:
1212

1313
1. In all platform head projects except UWP update the `Uno.UI` NuGet packages to 3.0 or above.
1414
1. In only the `UWP` head project of your solution, if you have one, install the [WinUI 2 NuGet package](https://www.nuget.org/packages/Microsoft.UI.Xaml). This step is the same as required for WinUI 2 UWP apps.
15-
1. Within the shared project used by all platform heads, add the `XamlControlsResources` resource dictionary to your application resources inside `App.xaml`. This step is the same as required for WinUI 2 UWP apps.
15+
1. Within the shared project used by all platform heads, add the `XamlControlsResources` resource dictionary to your application resources inside `AppResources.xaml` or `App.xaml`. This step is the same as required for WinUI 2 UWP apps.
1616
```xml
1717
<Application>
1818
<Application.Resources>

doc/articles/features/native-frame-nav.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ On Android and iOS, there is the option to enable native frame navigation. Enabl
1313
- `Windows.UI.Xaml.Controls.CommandBar`
1414
- `Windows.UI.Xaml.Controls.AppBarButton`
1515

16-
This feature can be enabled by calling the method below, typically in the constructor of your `App` class in `App.xaml.cs`:
16+
This feature can be enabled by calling the method below, typically in the constructor of your `App` class in `App.cs` or `App.xaml.cs`:
1717
```cs
1818
#if __IOS__ || __ANDROID__
1919
Uno.UI.FeatureConfiguration.Style.ConfigureNativeFrameNavigation();

doc/articles/features/protocol-activation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Works according to Windows docs, see [Microsoft Docs](https://docs.microsoft.com
6969

7070
## Handling protocol activation
7171

72-
Custom URI activation can be handled by overriding the `OnActivated` method in `App.xaml.cs`:
72+
Custom URI activation can be handled by overriding the `OnActivated` method in `App.cs` or `App.xaml.cs`:
7373

7474
```
7575
protected override void OnActivated(IActivatedEventArgs e)
@@ -135,4 +135,4 @@ private Frame GetOrCreateRootFrame(IActivatedEventArgs eventArgs)
135135

136136
return rootFrame;
137137
}
138-
```
138+
```

doc/articles/features/resources-trimming.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ As of Uno 3.9, XAML Resources Trimming is only available for WebAssembly project
88

99
## Using XAML Resources trimming for applications
1010

11-
In order for an application to enable resources trimming, the following needs to be added in the project file:
11+
In order for an application to enable resources trimming, the following needs to be added to all projects of your solution that reference the Uno.WinUI (or Uno.UI) package, as well as the WebAssembly head project:
1212

1313
```xml
1414
<PropertyGroup>
1515
<UnoXamlResourcesTrimming>true</UnoXamlResourcesTrimming>
1616
</PropertyGroup>
1717
```
1818

19-
## Enabling XAML Resources trimming for libraries
19+
## Enabling XAML Resources trimming for libraries and NuGet Packages
2020
For libraries to be eligible for resources trimming, the `UnoXamlResourcesTrimming` tag must also be added.
2121

2222
## Troubleshooting

doc/articles/features/uno-material.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ For complete instructions on using Uno Material in your projects, check out this
3737
> Certain controls require [additional setup steps](uno-material-controls-extra-setup.md).
3838

3939
## Migrating From Previous Resource Initialization Method
40-
Prior to the `1.0` release, the initialization of Material resources was required to be done through code-behind within the `App.xaml.cs` file. Resource initialization has now been moved to XAML-only. Follow the steps below to migrate from the old method of initialization to the new one:
40+
Prior to the `1.0` release, the initialization of Material resources was required to be done through code-behind within the `App.cs` or `App.xaml.cs` file. Resource initialization has now been moved to XAML-only. Follow the steps below to migrate from the old method of initialization to the new one:
4141

42-
1. Remove the following code from `App.xaml.cs`
42+
1. Remove the following code from `App.cs` or `App.xaml.cs`
4343
```diff
4444
protected override void OnLaunched(LaunchActivatedEventArgs e)
4545
{
@@ -49,7 +49,7 @@ Prior to the `1.0` release, the initialization of Material resources was require
4949
}
5050

5151
```
52-
1. Add `MaterialColors` and `MaterialResources` to `App.xaml`:
52+
1. Add `MaterialColors` and `MaterialResources` to `AppResources.xaml` or `App.xaml`:
5353
```diff
5454
<Application.Resources>
5555
<ResourceDictionary>

doc/articles/features/using-linux-framebuffer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dotnet publish -c Release -r linux-x64 --self-contained true
4444
```
4545

4646
> [!NOTE]
47-
> When using the `Release` configuration, logging is disabled for performance considerations. You can restore logging in the App.xaml.cs file.
47+
> When using the `Release` configuration, logging is disabled for performance considerations. You can restore logging in the `App.xaml.cs` file.
4848
4949
Documentation on other hardware targets are [available here](https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md).
5050

doc/articles/features/windows-storage-pickers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);
4747
await picker.PickSingleFileAsync();
4848
```
4949

50-
To get the `Window` instance in single-window apps, it is easiest to create an `internal static MainWindow` property in the `App.xaml.cs` file, initialize it in `OnLaunched`, and then use it for this purpose:
50+
To get the `Window` instance in single-window apps, it is easiest to create an `internal static MainWindow` property in the `App.cs` or `App.xaml.cs` file, initialize it in `OnLaunched`, and then use it for this purpose:
5151

5252
```csharp
5353
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow);
@@ -355,16 +355,18 @@ namespace Custom.Pickers
355355
#endif
356356
```
357357

358-
When done, register this extension in `App.xaml.cs`:
358+
When done, register this extension in `App.cs` or `App.xaml.cs`:
359359

360360
```csharp
361361
public App()
362362
{
363+
...
363364
#if __IOS__
364365
ApiExtensibility.Register(
365366
typeof(Uno.Extensions.Storage.Pickers.IFileSavePickerExtension),
366367
picker => new CustomFileSavePickerExtension(picker));
367368
#endif
369+
...
368370
}
369371
```
370372

doc/articles/features/working-with-accessibility.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Instead of trying to replicate UWP's behavior on iOS (which *might* be doable us
3131
Here's how to enable it:
3232

3333
```csharp
34-
// App's constructor (App.xaml.cs)
34+
// App's constructor (`App.cs` or `App.xaml.cs`)
3535
#if __IOS__ || __ANDROID__ || __MACOS__ || __WASM__
3636
FeatureConfiguration.AutomationPeer.UseSimpleAccessibility = true;
3737
#endif
@@ -46,8 +46,8 @@ You have the option to disable accessibility text scaling of iOS and Android dev
4646
Here's how to disable it
4747

4848
```csharp
49-
// App's constructor (App.xaml.cs)
50-
Uno.UI.FeatureConfiguration.Font.IgnoreTextScaleFactor= true;
49+
// App's constructor (`App.cs` or `App.xaml.cs`)
50+
Uno.UI.FeatureConfiguration.Font.IgnoreTextScaleFactor = true;
5151
```
5252

5353
## AutomationId

doc/articles/features/working-with-assets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Because the `custom` qualifier doesn't have any special meaning on UWP, we have
135135

136136
On iOS and Android, Uno.UI's `RetargetAssets` task automatically interprets these values and excludes unsupported platforms.
137137

138-
On UWP, you must add the following code to your `App.xaml.cs` constructor:
138+
On UWP, you must add the following code to your `App.cs` or `App.xaml.cs` constructor:
139139

140140
```csharp
141141
#if WINDOWS_UWP

doc/articles/features/working-with-themes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Uno Platform supports `Light`, `Dark` and `HighContrast` themes similarly to UWP.
44

5-
As in UWP, the default theme is `Dark`, but in the case of Uno we use `Light` for all supported systems, as that is the default on all except Windows. However, if you don't specify a theme in the constructor of `App` and don't specify it in `App.xaml` either, it will be determined by the current system theme on iOS, Android and to current system/browser theme (depending on browser implementation) on WASM.
5+
As in UWP, the default theme is `Dark`, but in the case of Uno, we use `Light` for all supported systems, as that is the default on all except Windows. However, if you don't specify a theme in the constructor of `App` and don't specify it in `AppResources.xaml` or `App.xaml` either, it will be determined by the current system theme on iOS, Android and to current system/browser theme (depending on browser implementation) on WASM.
66

77
To set `HighContrast` theme or a custom theme, you can use the `Uno.UI.ApplicationHelper` class:
88

@@ -16,7 +16,7 @@ Setting `Application.Current.RequestedTheme` outside of `App` constructor is not
1616

1717
## Reacting to OS theme changes
1818

19-
If you don't specify the theme in `App` constructor and `App.xaml`, your app will automatically adapt to OS theme changes at runtime. However, on Android, you need to make sure to add `ConfigChanges.UiMode` to the `MainActivity` `[Application]` attribute, for example:
19+
If you don't specify the theme in `App` constructor and `AppResources.xaml` or `App.xaml`, your app will automatically adapt to OS theme changes at runtime. However, on Android, you need to make sure to add `ConfigChanges.UiMode` to the `MainActivity` `[Application]` attribute, for example:
2020

2121
``` c#
2222
[Activity(

doc/articles/guides/localization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This guide will walk you through the necessary steps to localize an Uno Platform
6161
Now, if you change the language of the targeted PC or the mobile device AND restart the app, that text should also change accordingly.
6262

6363
You can also set the starting culture to see the result, without having to modify the system language:
64-
- `App.xaml.cs`:
64+
- `App.cs` or `App.xaml.cs`:
6565
```cs
6666
public App()
6767
{

doc/articles/guides/native-frame-nav-tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The complete sample code can be found here: [NativeFrameNav](https://github.com/
5959
private void NavigateBack(object sender, RoutedEventArgs e) => Frame.GoBack(); // in both pages
6060
```
6161

62-
6. Enable native frame navigation in `App.xaml.cs`:
62+
6. Enable native frame navigation in `App.cs` or `App.xaml.cs`:
6363
```cs
6464
public App()
6565
{

doc/articles/guides/silverlight-migration/01-create-uno-solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ There are a few steps to adding WinUI 2.5 to the Uno project:
8383
> [!NOTE]
8484
> The [Uno.UI](https://www.nuget.org/packages/Uno.UI) NuGet package already includes the WinUI 2.x bits so there are no changes for the WASM head.
8585
86-
1. To add the WinUI resources to the app, open the **App.xaml** file and add the following:
86+
1. To add the WinUI resources to the app, open the `AppResources.xaml` or `App.xaml` file and add the following:
8787
8888
```xml
8989
<Application.Resources>

doc/articles/guides/silverlight-migration/03-review-app-startup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ Earlier application platforms had a simple lifecycle - once launched, they conti
3535
> * [App Lifecycle](https://docs.microsoft.com/windows/uwp/launch-resume/app-lifecycle)
3636
> * [Application Class](https://docs.microsoft.com/uwp/api/windows.ui.xaml.application?view=winrt-19041)
3737
38-
The Uno template generates a basic **App.xaml.cs** file that satisfies the minimum needs for app startup and suspension, and then configures the app to use a **Frame** control as the equivalent of the the Silverlight RootVisual, and then navigates to the **MainPage**, which displays "Hello, World!".
38+
The Uno template generates a basic `App.cs` and `App.xaml.cs` file that satisfies the minimum needs for app startup and suspension, and then configures the app to use a **Frame** control as the equivalent of the Silverlight RootVisual, and then navigates to the **MainPage**, which displays "Hello, World!".
3939

40-
Briefly reviewing the **App.xaml.cs** will reveal the following structure:
40+
Briefly reviewing the `App.cs` and `App.xaml.cs` files will reveal the following structure:
4141

4242
* **Constructor** - as well as initializing the application component, the app logging configuration method **ConfigureFilters** is called, and a subscription to the **Suspending** event is added.
4343
* **OnLaunched** - this method is called if the application is launched by the user - other methods (not implemented in this template) are called for other scenarios (see resources above). The current window is retrieved and the content is checked to see if a **Frame** is already instantiated (see note below). If not, a new frame is configured and set as the window content. The code then checks to see if the app has been prelaunched (see note below) - if not, and the root frame isn't already showing content, it is navigated to the **MainPage**. Finally the window is activated, which brings it to the foreground and applying input focus.
@@ -62,7 +62,7 @@ In order to better align with the behavior of the Silverlight version of the app
6262

6363
1. Return to the **TimeEntryUno** solution.
6464

65-
1. In the **[MyApp]** project, open the **App.xaml.cs** file
65+
1. In the **[MyApp]** project, open the **App.cs** file
6666

6767
1. Locate the **OnLaunched** method and replace it with the following code:
6868

doc/articles/guides/silverlight-migration/04-migrate-home-page-xaml-and-styles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ The next steps will show how migrate the Silverlight styles to work in the Uno a
164164

165165
1. Right-click the new **Resources** folder, select **Add &gt; New Item**, select **Resource Dictionary** and name it **Styles.xaml**.
166166

167-
To ensure the resource dictionary is loaded, it must be added to **App.xaml**.
167+
To ensure the resource dictionary is loaded, it must be added to **AppResources.xaml**.
168168

169-
1. Open **App.xaml** and the reference to the **Styles.xaml** as shown below:
169+
1. Open **AppResources.xaml** and the reference to the **Styles.xaml** as shown below:
170170

171171
```xml
172172
<Application.Resources>

doc/articles/guides/silverlight-migration/05-string-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In the Silverlight project, the application string resources are found within th
1212

1313
![String Resource Home Navigation Page Title](assets/StringResource-HomeNav.png)
1414

15-
The **ResourceWrapper** helper is instantiated in the application resources defined in **App.xaml** as:
15+
The **ResourceWrapper** helper is instantiated in the application resources defined in **AppResources.xaml** as:
1616

1717
```xml
1818
<ResourceDictionary>

doc/articles/guides/silverlight-migration/10-implementing-singleton-token-service.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ The next task will discuss an approach to initializing the service.
160160

161161
## TokenService initialization
162162

163-
As the **TokenService** utilizes asynchronous initialization, there is an advantage to starting the initialization process as early as feasible in the application lifecycle. An example would be adding it to the **App.xaml.cs OnLaunched** method, as shown below:
163+
As the **TokenService** utilizes asynchronous initialization, there is an advantage to starting the initialization process as early as feasible in the application lifecycle. An example would be adding it to the `App.cs` `OnLaunched` method, as shown below:
164164

165165
```csharp
166166
protected override void OnLaunched(LaunchActivatedEventArgs e)

doc/articles/guides/status-bar-theme-color.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The complete sample code can be found here: [StatusBarThemeColor](https://github
5050
public CommandBar GetCommandBar() => MyCommandBar;
5151
```
5252

53-
5. In `App.xaml.cs`, enable the native frame navigation to use the native style for `CommandBar`, instead of the UWP style. Make sure that the `#if ... #endif` block is before `this.InitializeComponent()`:
53+
5. In `App.cs`, enable the native frame navigation to use the native style for `CommandBar`, instead of the UWP style. Make sure that the `#if ... #endif` block is before `this.InitializeComponent()`:
5454
```cs
5555
public App()
5656
{
@@ -66,7 +66,7 @@ The complete sample code can be found here: [StatusBarThemeColor](https://github
6666
}
6767
```
6868

69-
6. Subscribe to the `UISettings.ColorValuesChanged` event from `App.xaml.cs`:
69+
6. Subscribe to the `UISettings.ColorValuesChanged` event from `App.cs`:
7070
> Note that the instance of `UISettings` is kept to prevent it from being disposed when going out of scope, which would otherwise dispose the event subscription.
7171
```cs
7272
public sealed partial class App : Application

0 commit comments

Comments
 (0)