首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin窗体将Xaml转换为公共资源样式Yummy

Xamarin窗体将Xaml转换为公共资源样式Yummy
EN

Stack Overflow用户
提问于 2020-12-10 15:12:53
回答 1查看 398关注 0票数 0

我正试图将我的煎饼控件的属性转换成一种样式,所以我所有的煎饼控件都是相同的样式。这就是我的XAML的样子。

代码语言:javascript
复制
    <yummy:PancakeView x:Name="pvMEssage" BackgroundColor="{DynamicResource ExceptionBackground}" CornerRadius="0,0,20,20" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                       Padding="0,0,0,0" Margin="0,0,0,0">
        <yummy:PancakeView.BackgroundGradientStops StartPoint="0,0" EndPoint="0,0">
            <yummy:GradientStop Offset="0.1" Color="{DynamicResource ExceptionBackground}" />
        </yummy:PancakeView.BackgroundGradientStops>
        <yummy:PancakeView.Border>
            <yummy:Border Color="White" Thickness="2" />
        </yummy:PancakeView.Border>

我知道如何在样式中使用setter.value,但我不知道如何在样式中放置背景梯度。

到目前为止,我有这样的看法:

代码语言:javascript
复制
            <Style x:Key="PancakeViewTop" TargetType="yummy:PancakeView">
            <Setter Property="CornerRadius" Value="20,20,0,0" />
            <Setter Property="HorizontalOptions" Value="FillAndExpand" />
            <Setter Property="VerticalOptions" Value="FillAndExpand" />
            <Setter Property="Padding" Value="0,0,0,0" />
            <Setter Property="Margin" Value="0,0,0,0" />
            <Setter Property="BackgroundGradientStartPoint" Value="0,0" />
            <Setter Property="BackgroundGradientEndPoint" Value="0,0" />
            <Setter Property="BackgroundGradientStops">
                <Setter.Value>
                    <yummy:GradientStop Offset="0.1" Color="{DynamicResource ExceptionBackground}" />
                </Setter.Value>
            </Setter>
            <Setter Property="Border">
                <Setter.Value>
                    <yummy:Border Color="White" Thickness="2" />
                </Setter.Value>
            </Setter>
        </Style>

但我在这几行上有个错误

代码语言:javascript
复制
<Setter Property="BackgroundGradientStops">
    <Setter.Value>

它声明“指定的值不能赋值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-10 16:09:49

试着:

代码语言:javascript
复制
<Setter Property="BackgroundGradientStops">
    <Setter.Value>
        <pancake:GradientStopCollection>
            <pancake:GradientStop Offset="0.1" Color="{DynamicResource ExceptionBackground}"/>
            <pancake:GradientStop Offset="0.5" Color="{DynamicResource OtherColor}"/>
        </pancake:GradientStopCollection>
    </Setter.Value>
</Setter>

另外,您需要指定至少2种颜色(2 GradientStop),否则会引发异常。

Java.Lang.IllegalArgumentException:“需要>= 2色数”

而且它不会使感光变成只有一种颜色的渐变。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65237175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档