我在 Xaml 中定义了这样的列表。
<ContentPage.Resources>
<ResourceDictionary>
<local:FileName x:Key="fileName">
<Color>#3599B8</Color>
<Color>#374649</Color>
<Color>#FD625E</Color>
<Color>#F2C80F</Color>
</local:FileName>
</ResourceDictionary>
</ContentPage.Resources>
FileName 是这样在代码后面定义的。
public class FileName : List<Color>
{
}
我不想直接设置颜色值,而是想像这样将其定义为资源
<Color x:Key="BasicColorSchemeBlue">#3599B8</Color>
并使用它。
有关如何执行此操作的任何建议。
提前致谢。
最佳答案
GradientColors is an array of Colors.
<?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:GradientTest"
xmlns:s="clr-namespace:System;assembly=mscorlib"
x:Class="GradientTest.GradientTestPage">
<StackLayout Padding="20, 40, 20, 20">
<local:GradientViewRender HorizontalOptions="Center"
WidthRequest="300"
HeightRequest="50"
x:Name="gradientView">
<local:GradientViewRender.GradientColors>
<x:Array Type="{x:Type Color}">
<Color>#5FC900</Color>
<Color>#0FF2C8</Color>
</x:Array>
</local:GradientViewRender.GradientColors>
</local:GradientViewRender>
</StackLayout>
</ContentPage>
关于xaml - Xaml 中的列表<颜色>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43876853/