如何更改 .NET MAUI Community Toolkit 弹出式窗口的黑色透明背景?

huangapple go评论74阅读模式
英文:

How to change the black transparent backdrop of a .NET MAUI Community Toolkit Popup?

问题

当使用.ShowPopup()方法从.NET MAUI Community Toolkit中调用Popup元素时,视图会显示在一个黑色透明的背景前面。如何更改该背景的颜色(最好是透明的)?

据我所知,Popup元素本身没有允许进行此类更改的属性。我最好的猜测是,这种行为由iOS/Android平台的代码控制。如果是这样,我该如何实现这种更改?

在此先感谢您的回复。

英文:

when calling a Popup-Element from the .NET MAUI Community Toolkit with the .ShowPopup() method, the View is presented in front of a black transparent backdrop. How can I change the color of said backdrop (preferable to clear transparent)?

As far as I can tell, there are no properties of the Popup-Element itself that allows me this kind of change. My best guess is, that this behavior is controlled by iOS/Android platform code. If so, how can I implement this change?

Thank you in advance for your replies.

答案1

得分: 1

I believe there should have existed a property like BackgroundColor of Popup so it can allow us to easily change it. However, according to Properties, these properties are all related with the Popup rather than the backdrop area that we want to customize.

作为目前的替代解决方案,您可以使用 Mopups,使您能够在您的 .NET MAUI 应用程序内创建高度可定制的弹出窗口。您可以通过 BackgroundColor 轻松更改所述背景的颜色,我将其设置为 #F4FAFC,这是“透明清晰”的颜色。

<?xml version="1.0" encoding="utf-8" ?>
<mopups:PopupPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiAppPopups.MyPopupPage"
             xmlns:mopups="clr-namespace:Mopups.Pages;assembly=Mopups"
             BackgroundColor="#F4FAFC"
             CloseWhenBackgroundIsClicked="True"
             Title="MyPopupPage">
    <VerticalStackLayout WidthRequest="250" HeightRequest="500" VerticalOptions="CenterAndExpand" BackgroundColor="Yellow">
        <Label 
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center" 
            HorizontalOptions="Center" />
    </VerticalStackLayout>
</mopups:PopupPage>

有关更多详细信息,您可以参考 Popups For MAUI

英文:

I believe there should have existed a property like BackgroundColor of Popup so it can allow us to easily change it. However, according to Properties, these properties are all related with the Popup rather than the backdrop area that we want to customize.

As an alternative workaround for now, you can use Mopups enabling you to create highly customizable popups inside of your .NET MAUI apps. You can easily change the color of said backdrop via BackgroundColor, I set it to #F4FAFC which is clear transparent.


&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; 
&lt;mopups:PopupPage xmlns=&quot;http://schemas.microsoft.com/dotnet/2021/maui&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
             x:Class=&quot;MauiAppPopups.MyPopupPage&quot;
             xmlns:mopups=&quot;clr-namespace:Mopups.Pages;assembly=Mopups&quot;
                  
             BackgroundColor=&quot;#F4FAFC&quot;

             CloseWhenBackgroundIsClicked=&quot;True&quot;
                  
             Title=&quot;MyPopupPage&quot;&gt;
    &lt;VerticalStackLayout WidthRequest=&quot;250&quot; HeightRequest=&quot;500&quot; VerticalOptions=&quot;CenterAndExpand&quot; BackgroundColor=&quot;Yellow&quot;&gt;
        &lt;Label 
            Text=&quot;Welcome to .NET MAUI!&quot;
            VerticalOptions=&quot;Center&quot; 
            HorizontalOptions=&quot;Center&quot; /&gt;
    &lt;/VerticalStackLayout&gt;
    
&lt;/mopups:PopupPage&gt;

For more details, you can refer to Popups For MAUI.

huangapple
  • 本文由 发表于 2023年3月7日 23:22:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663874.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定