如何在.NET MAUI应用程序中将页面设置为具有线性背景?
我尝试在Colors.xaml
中定义一个LinearGradientBrush
,然后将其分配为StaticResource
(见下文),但这似乎不起作用。
在Colors.xaml
中,我有:
<LinearGradientBrush x:Key="PageGradientBackground" EndPoint="1,1">
<GradientStop
Color="{StaticResource UIOffWhite}"
Offset="0.1"/>
<GradientStop
Color="{StaticResource UILightGray}"
Offset="0.6"/>
<GradientStop
Color="{StaticResource UIMidGray}"
Offset="1.0"/>
</LinearGradientBrush>
然后像这样使用它:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="{StaticResource PageGradientBackground}">
<!-- ... -->
</ContentPage>
我也尝试过内联定义它,但也不起作用。实际上这是不允许的:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentPage.BackgroundColor>
<LinearGradientBrush>
</LinearGradientBrush>
</ContentPage.BackgroundColor>
<!-- ... -->
</ContentPage>
有什么想法,我可以有一个梯度背景的ContentPage
?
1条答案
按热度按时间vbkedwbf1#
你可以像下面的代码一样使用
LinearGradientBrush
。你可以把LinearGradientBrush
放在<ContentPage.Background>
中,它可以很好地工作。有关更多信息,请参阅本文Linear gradient brushes。