列表<颜色>在Xaml中 [英] List<Color> in Xaml
本文介绍了列表<颜色>在Xaml中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Xaml中定义了这样的列表.
I have my List defined in Xaml like this.
<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像这样在后面的代码中定义.
FileName is defined in code behind like this.
public class FileName : List<Color>
{
}
我不想直接设置Color值,而是将其定义为这样的资源
Instead of directly setting the Color values, i want to define it as resource like this
<Color x:Key="BasicColorSchemeBlue">#3599B8</Color>
并使用它.
有关如何执行此操作的任何建议.
Any suggestions on how to do this.
谢谢.
推荐答案
GradientColors是颜色的数组.
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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文