Xamarin.forms 更新到.forms 3.1后,更改了操作栏和页面的背景颜色
我正在更新我的.forms(共享)项目:Xamarin.forms 更新到.forms 3.1后,更改了操作栏和页面的背景颜色,xamarin.forms,xamarin.android,Xamarin.forms,Xamarin.android,我正在更新我的.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)中: 动作(标题)栏的背景
- VS2015更新3 RC->VS2017 15.7.5
- .forms 2.3.0.49->.forms 3.1
然后,我将整个项目更新为表格3.1(设置/代码没有任何进一步更改)。
之后,颜色会自动更改,使应用程序无法使用。
在旧版本(.forms 2.3.0)中:
- 动作(标题)栏的背景色为白色,而 标题文本颜色为黑色
- 页面背面颜色为黑色(因此我将文本颜色设置为白色和浅绿色,在黑色背景下可读性良好)
- 动作(标题)栏的背景色为黑色,标题 文本颜色也(仍然)为黑色(不可读/不可用)
- 页面背面颜色为白色,文本颜色仍然为白色和浅绿色(不可读/不可用)
有人知道为什么会发生这种情况,以及我必须如何设置整个应用程序的“旧”基本背景颜色吗?我仍然不知道为什么更新到.forms 3.1会更改颜色,但我找到了一个解决方案来设置我的应用程序的颜色 正如我所写,我还没有使用XAML,而是使用.forms 2.3.0.49和VS2015(很久以前)创建了我的.forms项目。 因此,我的项目在共享目录中只有一个app.cs作为主要入口点(没有一个app.xaml,在这里可以定义应用程序的基本颜色) 因此,我更改了我的应用程序关于app.cs的设计。
为此,我必须:
- 从我的项目中排除app.css文件
- 基于模板“内容页”(描述“使用XAML显示内容的页面”)向我的项目添加一个新文件
- 将新文件命名为App
- App.xaml(应用程序对象的新描述文件)
- App.xaml.cs(应用程序对象的新代码文件)
必须设置app.xaml的以下属性:
构建操作:嵌入式资源
自定义工具:MSBuild:UpdateDesignTimeXaml
(注意:我必须手动输入文本) 然后,我必须将“旧”app.cs文件的内容复制到app.xaml.cs文件中,并进行以下更改:
更改: 致: 进一步确保:
public App()
{}
包含:
InitializeComponent();
(注意:在我的案例中,这是不存在的)
安全,该App.xaml在Class=entry中包含正确的应用程序名称
x:Class="YourCorrectAppName.App"><Application.Resources>
x:Class=“YourCorrectAppName.App”>
然后:
- 将所有文件保存到项目中
- 清洁工程
- 重新打开项目
- 编制项目
项目编译完成后,我就可以打开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>
现在,我的项目又可以使用了
x:Class="YourCorrectAppName.App"><Application.Resources>
<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>