I still don’t know why the colors were changed by the update to .forms 3.1, but I have found a solution to set the colors to my app.
As I wrote, I don’t have worked with XAML yet and had created my .forms project with .forms 2.3.0.49 and VS2015 (a longer time ago).
Therefore, my project only had an app.cs as main entry point in the shared directory (without an app.xaml where it should be possible to define the base colors to the app).
Therefore, I have changed the design of my app regarding the app.cs.
To do this, I had to:
- Exclude the file app.css from my project
- Add a new file to my project, based on template “Content Page” (description “A page for displaying content using XAML”)
- Name the new file App
Then, two files were generated:
- App.xaml (the new description file to the app object)
- App.xaml.cs (the new code file to the app object)
Secure, that both new files are included in the project.
The following properties to the app.xaml have to be set:
Build Action: Embedded resource
Custom Tool: MSBuild:UpdateDesignTimeXaml
(note: I had to enter the text manually)
Then, I had to copy the content of the “old” app.cs file in the file app.xaml.cs and do the following changes:
Change:
public class App : Application
to:
public partial class App : Application
further secure, that:
public App()
{}
contains:
InitializeComponent();
(note: this was missing in my case)
Secure, that App.xaml contains the correct name of the app in the Class= entry
x:Class="YourCorrectAppName.App"><Application.Resources>
Then:
- Save all files to the project
- Clean project
- Reopen project
- Compile the project
(Note: I had to reload the project multiple times until VS has noted all changes, by first attempt, I had error messages by trying to compile).
As soon as the project has compiled, I was able to open App.xaml and set the needed base colors to my project in App.xaml:
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CSCockpit.App">
<Application.Resources>
<ResourceDictionary>
<!-- Platformspecific settings to the app -->
<!-- Important!
ApplyToDerivedTypes="True" include the change to all derived types (only this way it works!) -->
<!-- ContentPage -->
<!-- Set background color to ContentPage depending on platform -->
<Style
TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter
Property="BackgroundColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="Black"
iOS="White"
WinPhone="White" />
</Setter.Value>
</Setter>
</Style>
<!-- NavigationPage -->
<!-- Set BarTextColor color to NavigationPage depending on platform -->
<Style
TargetType="NavigationPage" ApplyToDerivedTypes="True">
<Setter
Property="BarTextColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="White"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
</Style>
<!-- Entry -->
<!-- Set text- and placeholder color to entry depending on platform -->
<Style
TargetType="Entry" ApplyToDerivedTypes="True">
<Setter
Property="TextColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="White"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
<Setter
Property="PlaceholderColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="SlateGray"
iOS="SlateGray"
WinPhone="SlateGray" />
</Setter.Value>
</Setter>
</Style>
<!-- Editor -->
<!-- Set text color to entry depending on platform -->
<Style
TargetType="Editor" ApplyToDerivedTypes="True">
<Setter
Property="TextColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="White"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
</Style>
<!-- Picker -->
<!-- Set font size and text color to pircker depending on platform -->
<Style
TargetType="Picker" ApplyToDerivedTypes="True">
<Setter
Property="TextColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="White"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
<Setter
Property="FontSize">
<Setter.Value>
<OnPlatform
x:TypeArguments="x:Double"
Android="18"
iOS="20"
WinPhone="20" />
</Setter.Value>
</Setter>
</Style>
<!-- DatePicker -->
<!-- Set font size and text color to picker depending on platform -->
<Style
TargetType="DatePicker" ApplyToDerivedTypes="True">
<Setter
Property="TextColor">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="White"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
<Setter
Property="FontSize">
<Setter.Value>
<OnPlatform
x:TypeArguments="x:Double"
Android="18"
iOS="20"
WinPhone="20" />
</Setter.Value>
</Setter>
</Style>
<Style
TargetType="BoxView" ApplyToDerivedTypes="True">
<Setter
Property="Color">
<Setter.Value>
<OnPlatform
x:TypeArguments="Color"
Android="SlateGray"
iOS="Black"
WinPhone="Black" />
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Now, my project is usable again...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…