以xamarin形式创建自定义框架

问题描述 投票:0回答:1

enter image description here

我必须像在所附照片中那样创建一个框架,因为它必须包含标签/文字,并且必须具有高程和阴影,因此它必须具有适应性。用框架很容易做到所有这些,问题是说话很少,我找不到找到方法。

[也许有人有一个开始的想法。谢谢

xamarin xamarin.forms custom-controls frame
1个回答
0
投票

您可以将框架的HeightWidth与其子元素(如标签)绑定在一起。

在后面的代码中

public class SizeConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((double)value + 20.0); // you can set the logic of height and width here  
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return 0;
    }
}

在xaml中

<ContentPage.Resources>
    <ResourceDictionary>
        <local:SizeConverter x:Key="SizeConverter" />
    </ResourceDictionary>
</ContentPage.Resources>

<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <Frame CornerRadius="10" WidthRequest="{Binding Source={x:Reference contentLabel}, Path=Width,Converter={StaticResource SizeConverter} ,Mode=OneWay}" MinimumHeightRequest="100" HeightRequest="{Binding Source={x:Reference contentLabel}, Path=Height,Converter={StaticResource SizeConverter} ,Mode=OneWay}" BackgroundColor="LightBlue" Padding="10" >
        <!-- Place new controls here -->
        <Label x:Name="contentLabel"  BackgroundColor="LightGray" Text="xxx" 
       HorizontalOptions="Center"
       VerticalOptions="CenterAndExpand" />
    </Frame>
</StackLayout>
© www.soinside.com 2019 - 2024. All rights reserved.