Xamarin 为选择器设置背景图像

Xamarin 为选择器设置背景图像,xamarin,xamarin.ios,xamarin.android,xamarin.forms,Xamarin,Xamarin.ios,Xamarin.android,Xamarin.forms,我想设置一个像这样的背景图像 这是我的选取器的背景: 我尝试使用以下代码: <Grid > <Image Source="input_mobile_code_brown.png" x:Name="img"></Image> <Picker></Picker> </Grid> 但它首先显示选择器,然后显示堆栈布局方向等图像。您可以使用定位控件。我为您写了一个例子,您可以编辑RelativeLayout以适应您的场景

我想设置一个像这样的背景图像

这是我的选取器的背景:

我尝试使用以下代码:

<Grid >
<Image Source="input_mobile_code_brown.png" x:Name="img"></Image>
<Picker></Picker>
</Grid>

但它首先显示选择器,然后显示堆栈布局方向等图像。

您可以使用定位控件。我为您写了一个例子,您可以编辑RelativeLayout以适应您的场景

    <RelativeLayout Margin="0,20,0,0">
        <Image Source="pickerbackgroundimage.png" Aspect="AspectFit"  x:Name="img"
                   RelativeLayout.XConstraint =
                        "{ConstraintExpression Type=RelativeToParent,
                             Property=Width,
                             Factor=0,
                             Constant=0}"
                    RelativeLayout.YConstraint =
                        "{ConstraintExpression Type=RelativeToParent,
                             Property=Height,
                             Factor=0,
                             Constant=0}"
               />


        <Picker BackgroundColor="Transparent" x:Name="picker" 
                    RelativeLayout.XConstraint =
                        "{ConstraintExpression Type=RelativeToParent,
                             Property=Width,
                             Factor=0,
                             Constant=0}"
                    RelativeLayout.YConstraint =
                        "{ConstraintExpression Type=RelativeToParent,
                             Property=Height,
                             Factor=0,
                             Constant=0}"
                    RelativeLayout.WidthConstraint =
                        "{ConstraintExpression Type=RelativeToView,
                             ElementName=img,
                             Property=Width,
                             Factor=1,
                             Constant=0}"
                   RelativeLayout.HeightConstraint =
                        "{ConstraintExpression Type=RelativeToView,
                             ElementName=img,
                             Property=Height,
                             Factor=1,
                             Constant=0}"
                />

     </RelativeLayout>

它在iOS和Android上的工作原理如下: