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

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

问题描述

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

  • VS2015 Update 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)

  • 操作(标题)栏的背景颜色为黑色,标题 文本颜色也(仍然是)黑色(不可读/不可用)
  • 页面返回颜色是白色,白色,文本颜色仍然是白色和浅绿色(不可读/不可用)
  • The background color of the action (title) bar is black and the title text color also (still is) black (not readable / usable)
  • The page back colors is white are white and the text color still is white and light green (not readable / usable)

其他颜色(例如,编辑控件)的更改方式也很差(旧:深灰色背景和白色文字颜色,新:深灰色背景和黑色文字颜色)

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

由于我不想将颜色更改为应用程序中任何使用过的对象,因此我寻找一种方法来像.2.3.0中一样使用".forms 3.1"恢复"颜色设置,但未找到还没有任何有用的信息(现在尝试).

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显示内容的页面")向我的项目添加新文件
  • 命名新文件 App

然后,生成了两个文件:

Then, two files were generated:

  • App.xaml(新的描述文件到应用程序对象)
  • App.xaml.cs(应用对象的新代码文件)
  • App.xaml (the new description file to the app object)
  • App.xaml.cs (the new code file to the app object)

请确保两个新文件都包含在项目中.
必须设置 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天全站免登陆