【发布时间】:2021-08-05 23:06:21
【问题描述】:
我在 Xamarin.Forms 应用程序中为 Time 和 DatePickers 的样式和着色而苦苦挣扎。目前它是亮粉色(呃),我正在拼命寻找在整个项目 xaml 中改变它的可能性 - 文件“App.xaml” 我只发现了如何为按钮的背景着色,而不是对话框本身。
-> 我也在这里看到了这个问题:change the colour of DatePicker [Xamarin.Forms],但我不想在 Android 项目本身中更改它。我正在寻找一种自定义这些对话框的全局方法。
我的 App.xaml 代码:
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Arbeitszeitrechner_Forms.App">
<!--
Define global resources and styles here, that apply to all pages in your app.
-->
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Primary">#77C9D4</Color> <!-- Feather -->
<Color x:Key="Feather">#77C9D4</Color>
<Color x:Key="Marine">#57BC90</Color>
<Color x:Key="Forest">#015249</Color>
<Color x:Key="SleekGrey">#A5A5AF</Color>
<Style TargetType="Button">
<Setter Property="TextColor" Value="{StaticResource Marine}"></Setter>
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{StaticResource Forest}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{StaticResource Forest}" />
<Setter Property="Opacity" Value="0.1"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<Style TargetType="TimePicker">
<Setter Property="BackgroundColor" Value="{StaticResource Marine}"/>
<Setter Property="Background" Value="{StaticResource Forest}"/>
</Style>
<Style TargetType="DatePicker">
<Setter Property="BackgroundColor" Value="{StaticResource Marine}"/>
<Setter Property="Background" Value="{StaticResource Forest}"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
以及调用日期和时间选择器的页面(我跳过了无趣的部分;-);
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Arbeitszeitrechner_Forms"
x:Class="Arbeitszeitrechner_Forms.Views.CalcPage"
Title="{Binding Title}">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<Grid
Padding="10">
.
.
.
<TimePicker Grid.Row="1"
Grid.Column="0"
x:Name="BtnTime1"
Format="t"
PropertyChanged="OnTimePickerPropertyChanged" />
.
.
.
<DatePicker Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2"
x:Name="BtnDate"
Format="t"
PropertyChanged="OnTimePickerPropertyChanged" />
但是,目前看起来是这样的:
【问题讨论】:
-
picker是原生平台控件,如果在各个平台项目中单独修改,需要单独修改
标签: c# xamarin.forms