更新到 .forms 3.1 后更改了操作栏和页面的背景颜色 [英] Changed background colors of action bar and pages after update to .forms 3.1

查看:21
本文介绍了更新到 .forms 3.1 后更改了操作栏和页面的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新我的.forms(共享)项目:

  • VS2015 更新 3 RC -> VS2017 15.7.5
  • .forms 2.3.0.49 -> .forms 3.1

重要说明:我还没有使用 XAML(我在代码中做任何事情).

首先我编译了旧"项目,没有更新表单 -> 颜色与在 VS2015 下用 .forms 2.3.0 编译的颜色相同.
然后我已将整个项目更新为表格 3.1(在设置/代码中没有任何进一步的更改).
之后,颜色会自动更改,因此该应用程序无法使用.
版本(.forms 2.3.0)中:

First I have compiled the "old" project without to update forms -> the colors were identical to the compile with .forms 2.3.0 under VS2015.
Then I have updated the whole project to forms 3.1 (without any further change in the settings / code).
After that, the colors were changed automatically so that the app becomes unusable.
In the old version (.forms 2.3.0):

  • 动作(标题)栏的背景色为白色,标题文字颜色为黑色

  • The background color of the action (title) bar was white and the title text color was black

页面背景颜色为黑色(因此我将文本颜色设置为白色和浅绿色,黑色背景下可读性良好)

The page back colors were black (therefore I have set the text colors to white and light green, what was good readable on the black background)

版本(.forms 3.1)

In the new version (.forms 3.1)

  • 动作(标题)栏的背景色为黑色,标题为黑色文本颜色也(仍然是)黑色(不可读/可用)
  • 页面背面颜色为白色,文字颜色仍为白色和浅绿色(不可读/不可用)

另外的颜色(例如编辑控件)也以一种糟糕的方式改变了(旧:深灰色背景和白色文本颜色,新:深灰色背景和黑色文本颜色).

Also further colors (e.g. to the edit control) were changed in a bad way (old: dark grey background and white text color, new: dark gray background and black text color).

所以...在 .forms 2.3.0 和 .forms 3.1 之间发生了一些变化 - 也许我的项目中缺少某些设置/文件到基本颜色设置...?

So... something has changed between .forms 2.3.0 and .forms 3.1 - maybe some setting / file is missing in my project to the base color settings...?

由于我不想更改应用程序中任何已使用对象的颜色,因此我搜索了一种使用 .forms 3.1 像在 2.3.0 中那样恢复"颜色设置的方法,但没有找到任何有用的信息(现在正在尝试).

As I don’t want to change the colors to any used objects in my app, I search for a way to "restore" the color settings with .forms 3.1 like it was in 2.3.0 but don’t have found any useful information’s yet (trying for day’s now).

有谁知道为什么会发生这种情况以及我必须做什么才能为整个应用程序设置旧"基本背景颜色?

Does anybody knows, why this happens and what I have to do to set the "old" base background colors for the whole app?

推荐答案

我仍然不知道为什么颜色会因更新到 .forms 3.1 而改变,但我已经找到了一个解决方案来为我的应用程序设置颜色.

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.

正如我所写,我还没有使用过 XAML,并且已经使用 .forms 2.3.0.49 和 VS2015(很久以前)创建了我的 .forms 项目.因此,我的项目只有一个 app.cs 作为共享目录中的主要入口点(没有 app.xaml 应该可以定义应用程序的基本颜色).

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).

因此,我更改了有关 app.cs 的应用程序设计.
为此,我必须:

Therefore, I have changed the design of my app regarding the app.cs.
To do this, I had to:

  • 从我的项目中排除文件 app.css
  • 基于模板内容页面"(描述使用 XAML 显示内容的页面")向我的项目添加一个新文件
  • 为新文件命名应用

然后,生成了两个文件:

Then, two files were generated:

  • App.xaml(应用对象的新描述文件)
  • App.xaml.cs(应用对象的新代码文件)

确保两个新文件都包含在项目中.
必须为 app.xaml 设置以下属性:
构建操作:嵌入式资源
自定义工具:MSBuild:UpdateDesignTimeXaml
(注意:我必须手动输入文本)

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)

然后,我不得不将旧"app.cs 文件的内容复制到文件 app.xaml.cs 中并进行以下更改:
变化:

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

到:

public partial class App : Application

进一步确保:

public App()
{}

包含:

InitializeComponent();

(注意:这在我的情况下丢失了)

(note: this was missing in my case)

安全,App.xaml 在 Class= 条目中包含正确的应用程序名称

Secure, that App.xaml contains the correct name of the app in the Class= entry

x:Class="YourCorrectAppName.App"><Application.Resources>  

那么:

  • 将所有文件保存到项目
  • 清理项目
  • 重新打开项目
  • 编译项​​目

(注意:我不得不多次重新加载项目,直到 VS 注意到所有更改,第一次尝试时,我尝试编译时收到错误消息).
项目编译完成后,我就可以打开 App.xaml 并在 App.xaml 中为我的项目设置所需的基本颜色:

(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...

这篇关于更新到 .forms 3.1 后更改了操作栏和页面的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆