如何在Xamarin(xaml代码)中创建半透明框架?
我根据Youtube上的教程制作了一个体重指数计算器。我在我的应用程序中添加了一张壁纸。我想在我的背景中添加一个透明的框架,所有的控件都会放在这个框架上。我希望控件具有完全不透明度。 我尝试了以下代码:如何在Xamarin(xaml代码)中创建半透明框架?,xaml,xamarin,Xaml,Xamarin,我根据Youtube上的教程制作了一个体重指数计算器。我在我的应用程序中添加了一张壁纸。我想在我的背景中添加一个透明的框架,所有的控件都会放在这个框架上。我希望控件具有完全不透明度。 我尝试了以下代码: <Frame BackgroundColor="Black" CornerRadius="10" HasShadow="False" Op
<Frame BackgroundColor="Black"
CornerRadius="10"
HasShadow="False"
Opacity="0.5"
Margin="30">
<FlexLayout Direction="Column"
JustifyContent="SpaceEvenly"
Padding="5">
<StackLayout Opacity="1">
<Label Text="قد شما چند سانتیمتر است؟"
Style="{StaticResource TitleStyle}"/>
<Label Text="{Binding Source={x:Reference HeightSlider},
Path=Value,
StringFormat='{0:F0} cm'}"
Style="{StaticResource ValueStyle}"/>
<Slider x:Name="HeightSlider"
Maximum="220"
Minimum="40"
Value="{Binding Height}"/>
</StackLayout>
<StackLayout Opacity="1">
<Label Text="وزن شما چند کیلوگرم است؟"
Style="{StaticResource TitleStyle}"/>
<Label Text="{Binding Source={x:Reference WeightSlider},
Path=Value,
StringFormat='{0:F0} kg'}"
Style="{StaticResource ValueStyle}"/>
<Slider x:Name="WeightSlider"
Maximum="150"
Minimum="5"
Value="{Binding Weight}"/>
</StackLayout>
<StackLayout Opacity="1">
<Label Text="شاخص توده بدنی شما:"
Style="{StaticResource LabelStyle}"/>
<Label Text="{Binding BMI}"
Style="{StaticResource LabelStyle}"
FontSize="48"/>
<Label Text="{Binding Classification}"
Style="{StaticResource LabelStyle}"
FontSize="20"/>
</StackLayout>
</FlexLayout>
</Frame>
问题是所有控件的不透明度和填充都继承自父节点。如何在保持边框透明度的同时为控件设置特定的填充和完全不透明度?您可以使用BoxView,并且不要忘记在
FlexLayout
中设置相同的边距
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="TitleStyle" TargetType="Label">
<Setter Property="BackgroundColor" Value="Green"></Setter>
</Style>
<Style x:Key="ValueStyle" TargetType="Label">
<Setter Property="BackgroundColor" Value="Red"></Setter>
</Style>
<Style x:Key="LabelStyle" TargetType="Label">
<Setter Property="BackgroundColor" Value="Yellow"></Setter>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Grid>
<BoxView x:Name="frame"
CornerRadius="10"
Opacity="0.5"
Margin="30">
</BoxView>
<FlexLayout Margin="30" Direction="Column"
JustifyContent="SpaceEvenly"
Padding="5">
<StackLayout Opacity="1">
<Label Text="قد شما چند سانتیمتر است؟"
Style="{StaticResource TitleStyle}"/>
<Label Text="{Binding Source={x:Reference HeightSlider},
Path=Value,
StringFormat='{0:F0} cm'}"
Style="{StaticResource ValueStyle}"/>
<Slider x:Name="HeightSlider"
Maximum="220"
Minimum="40"
Value="{Binding Height}"/>
</StackLayout>
<StackLayout Opacity="1">
<Label Text="وزن شما چند کیلوگرم است؟"
Style="{StaticResource TitleStyle}"/>
<Label Text="{Binding Source={x:Reference WeightSlider},
Path=Value,
StringFormat='{0:F0} kg'}"
Style="{StaticResource ValueStyle}"/>
<Slider x:Name="WeightSlider"
Maximum="150"
Minimum="5"
Value="{Binding Weight}"/>
</StackLayout>
<StackLayout Opacity="1">
<Label Text="شاخص توده بدنی شما:"
Style="{StaticResource LabelStyle}"/>
<Label Text="{Binding BMI}"
Style="{StaticResource LabelStyle}"
FontSize="48"/>
<Label Text="{Binding Classification}"
Style="{StaticResource LabelStyle}"
FontSize="20"/>
</StackLayout>
</FlexLayout>
</Grid>
</ContentPage.Content>