我正在更新我的.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( 中:
-
操作(标题(栏的背景颜色为白色,并且 标题文本颜色为黑色
-
页面背面的颜色是黑色的(因此我将文本颜色设置为白色和浅绿色,在黑色背景上可读性很好(
在新版本中(.forms 3.1(
- 操作(标题(栏的背景色为黑色,标题 文本颜色也(仍然是(黑色(不可读/可用( 页面背面颜色为白色为白色
- ,文本颜色仍为白色和浅绿色(不可读/可用(
此外,其他颜色(例如编辑控件(以不好的方式更改(旧:深灰色背景和白色文本颜色,新:深灰色背景和黑色文本颜色(。
所以... .forms 2.3.0 和 .Forms 3.1 之间发生了一些变化 - 也许我的项目中缺少一些设置/文件到基色设置......?
由于我不想将颜色更改为应用程序中任何使用的对象,因此我寻找一种使用 .forms 3.1 "恢复"颜色设置的方法,就像在 2.3.0 中一样,但还没有找到任何有用的信息(现在尝试一天(。
有没有人知道,为什么会发生这种情况以及我必须做什么来为整个应用程序设置"旧"基本背景颜色?
我仍然不知道为什么更新到 .forms 3.1 会更改颜色,但我找到了为我的应用程序设置颜色的解决方案。
正如我所写,我还没有使用 XAML,并且已经使用 .forms 2.3.0.49 和 VS2015(很久以前(创建了我的 .forms 项目。 因此,我的项目只有一个应用程序.cs作为共享目录中的主入口点(没有 app.xaml,应该可以定义应用程序的基本颜色(。
因此,我更改了有关该应用程序.cs的应用程序设计。
为此,我必须:
- 从我的项目中排除文件应用.css
- 基于模板"内容页"(说明"用于使用 XAML 显示内容的页"(向我的项目添加新文件
- 将新文件命名为应用
然后,生成了两个文件:
- App.xaml(应用对象的新说明文件(
- App.xaml.cs(应用对象的新代码文件(
安全,两个新文件都包含在项目中。
必须设置app.xaml的以下属性:生成操作:嵌入的资源
自定义工具:MSBuild:UpdateDesignTimeXaml
(注意:
我必须手动输入文本(
然后,我必须在文件 app.xaml 中复制"旧"应用程序.cs文件的内容.cs并执行以下更改:更改:
public class App : Application
自:
public partial class App : Application
进一步确保:
public App()
{}
包含:
InitializeComponent();
(注意:在我的情况下缺少这一点(
安全,即 App.xaml 在 Class= 条目中包含应用的正确名称
x:Class="YourCorrectAppName.App"><Application.Resources>
然后:
- 将所有文件保存到项目
- 清洁项目
- 重新打开项目
- 编译项目
(注意:我不得不多次重新加载项目,直到 VS 注意到所有更改,第一次尝试时,我在尝试编译时收到错误消息(。
项目编译完成后,我能够打开 App.xaml 并在 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>
现在,我的项目再次可用...