gpt4 book ai didi

xamarin - 是否可以为 Xamarin 框架提供不同的边框颜色?

转载 作者:行者123 更新时间:2023-12-02 17:52:06 24 4
gpt4 key购买 nike

这是我的 XAML:

<Frame CornerRadius="1" HasShadow="false" Margin="10" 
BackgroundColor="White" BorderColor="Silver" Padding="0" >

我在 iOS 上的谷歌翻译上看到,他们使用类似框架的东西来包围设置中的不同行。然而,它们的顶部和底部边框颜色不同。

有谁知道是否有办法用框架来做到这一点?

enter image description here

最佳答案

您可以使用像这样的组件来实现这一点

BorderEntryComponent.xaml

<?xml version="1.0" encoding="UTF-8"?>
<StackLayout
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="X.Y.Z.BorderEntryComponent"

Spacing="0">
<BoxView
x:Name="TopBorder"
HeightRequest="2"
HorizontalOptions="FillAndExpand"
VerticalOptions="EndAndExpand" />
<Entry x:Name="Entry" />
<BoxView
x:Name="BottomBorder"
HeightRequest="2"
HorizontalOptions="FillAndExpand"
VerticalOptions="EndAndExpand" />
</StackLayout>

并且,在您的 BorderEntryComponent.xaml.cs

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Xamarin.Forms;

namespace X.Y.Z
{
public partial class BorderEntryComponent : StackLayout
{
public static readonly BindableProperty TopColorProperty =
BindableProperty.Create(nameof(TopColor), typeof(Color), typeof(BorderEntryComponent), default(Color), BindingMode.OneWay);

public static readonly BindableProperty BottomColorProperty =
BindableProperty.Create(nameof(BottomColor), typeof(Color), typeof(BorderEntryComponent), default(Color), BindingMode.OneWay);

public UnderlineEntryComponent()
{
InitializeComponent();
}

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);

if (propertyName == TopColorProperty.PropertyName)
{
this.TopBorder.Color = TopColor;
}
else if (propertyName == BottomColorProperty.PropertyName)
{
this.BottomBorder.Color = BottomColor;
}
}

public Color TopColor
{
get => (Color)GetValue(TopColorProperty);
set => SetValue(TopColorProperty, value);
}

public Color BottomColor
{
get => (Color)GetValue(BottomColorProperty);
set => SetValue(BottomColorProperty, value);
}
}
}

然后,您只需在 .xaml 上执行此操作即可

<components:UnderlineEntryComponent
TopColor = "Blue"
BottomColor = "Black" />

您可以阅读有关可绑定(bind)属性的更多信息 here

关于xamarin - 是否可以为 Xamarin 框架提供不同的边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53415394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com