graphql-dotnet 相关问题


在 Node.js 应用程序中调用 notFoundHandler() 后,GraphQL 路径无法访问

我在将 GraphQL 集成到 Node.js 应用程序时遇到问题。最初一切正常,但添加 notFoundHandler() 后,位于 localhost:3000/graphql 的 GraphQL 端点不再存在...


Maui dotnet 8 可与 dotnet build 配合使用 - 不在 Visual Studio for mac 17.6.7 内

我有一个毛伊岛解决方案,我从 dotnet 7 升级到 dotnet 8,它在 Visual Studio for mac 17.6.7 的 dotnet 命令行上失败,它构建得很好。我可以这样做吗?在 moc 视觉研究中构建...


如何通过GraphQL访问类IList成员?

我有一个像这样的简单 Graphql 查询 公共类查询 { 公共异步任务>书籍(int pageIndex,int pageSize) { var 数据 = 新...


dotnet 工具安装在 sdk:8.0.100-bookworm-slim 中挂起

我正在将应用程序从 NET6 迁移到 NET8。该应用程序是在 dockerfile 中构建的。为了进行代码分析,dotnet 工具“dotnet-sonarscanner”安装在构建映像中。 在N...


GraphQL API 错误 - 不可哈希类型:“StrawberryAnnotation” - 五十一个应用程序

文件“c:\ Users idan \ AppData \ Local \ Programs \ Python \ Python311 \ Lib \ site-packages \ graphql xecution xecute.py”,第1036行,在await_result中 返回 build_response(等待结果,错误)#...


使用 HotChocolate GraphQL 忽略对象中的方法

我有一个用 Hotchocolate 和 GraphQL 公开的类。 在这个类中,我有一些属性和一个具有以下签名的公共方法: 公开表达...


ChilliCream graphql:使用变量定义 order_by

我有一个有效的 graphql 查询: 查询 orderOnTheFly { 产品(订单:{ id:ASC,状态:ASC }) { 节点 { id 状态 } } } 现在我必须(在前端)实现用户选择哪个文件...


Graphql 日期范围作为输入字段

我正在为汽车库存实现一个 GraphQL API,它存储注册、inDate、outDate 等信息。 我需要实现一个 fetch API 来检索所有来的汽车的信息...


github graphQL API - 如何检索问题的项目项?

我是 github graphQL API 的新手,我一直在使用 github Entreprise Cloud 寻找以下问题的解决方案: 我有一个存储库“myRepo”,其中包含一个问题“myIssue...


无法访问我的 Docker 容器中的 GraphQL

我正在尝试连接到 docker 容器中的 GraphQL API,但我无法在 Postman 或 Web 浏览器中访问它。 我的 dockerfile 和 docker compose 文件可能有问题,但我没有...


dotnet集合源代码中内部数组的局部变量副本的目的是什么

作为 dotnet 集合 Stack.cs 源代码 公共 T Peek() { int 大小 = _size - 1; T[] 数组 = _array; if ((uint)size >= (uint)array.Length) { ThrowForEmptyStack(); ...


使用 EF Core 和 GraphQL 在 ASP.NET Core 中保留唯一的连续组编号

我正在使用 ASP.NET Core Minimal API (.NET 7) 和 Entity Framework Core、HotChocolate(用于 GraphQL)和 Microsoft SQL Server 数据库开发 API 后端。我遇到了一个特定的挑战...


Node / GraphQL 和 Koa:地址已在使用 :::3000

我正在尝试将 GraphQL 实现到我的 KoaJs 服务器。但是,每次 nodemon 在更改时重新启动时,我都会在控制台中收到错误: 错误:监听 EADDRINUSE:地址已在使用 :::3000...


Springboot 3.2.1(使用 Jetty)和 graphql-spqr-spring-boot-starter 1.0.0 出现错误

刚刚将 Spring Boot 升级到版本 3.2.1(使用 Jetty)并开始出现以下错误。知道如何解决这个问题吗?或者 graphql-spqr-spring-boot-starter:1.0.0 仅与旧版本兼容...


如何在jmeter中保存graphql用户令牌

我的应用程序使用graphql。我需要在 jmeter 中创建测试,所有请求都将在其中,从创建用户到删除用户。但我无法在每个请求中传递和替换令牌。 输入我...


我无法使用 Docker 运行应用程序

我使用 Visual Studio 创建了一个 ASP.NET Core Web API 项目并添加了我自己的 Dockerfile: 来自 mcr.microsoft.com/dotnet/sdk:8.0 AS 构建 工作目录/应用程序 复制 *.csproj ./ 运行 dotnet 恢复 复制 。 ....


将 dotnet core (.NET Core) 嵌入到 Windows/Linux 上的本机应用程序中

是否有可能将 dotnet core (.NET Core) 环境嵌入到本机进程中? 我的用例是现有的游戏服务器,我想在其中提供扩展游戏的可能性...


ASP.Net Core 容器在自定义端口 8080 上运行,但 ASP.Net 容器在 Docker Windows 中在固定端口 80 上运行

我根据以下图片制作了两个容器: ASP.NET核心 mcr.microsoft.com/dotnet/aspnet:8.0.0-windowsservercore-ltsc2019 网络应用程序 来自 mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsserv...


Otel 收集器未从 dotnet 获取日志

我有一个 dotnet 应用程序,可以将日志推送到酒店收集器。在本地,使用 docker compose 一切正常,但是当我尝试在 kubernetes 中运行相同的内容时,我只得到跟踪,但没有日志。 在


Azure 函数(dotnet-isolated)无法启动,并出现 Grpc.Core.RpcException:StatusCode="Unavailable" - Mac M1

我最近得到了一台Mac M1,并且正在设置我的机器以进行Azure Function(dotnet-isolated)开发。 我按照下面的文档进行操作,该文档在我的 Windows 10 计算机上运行得非常好。


使用 GraphQL Apollo 同时进行轮询和分页?

要使用 Apollo 实现分页,您通常会使用发送查询时提供的 fetchMore 函数,结合 updateQuery 告诉 Apollo 如何更新其缓存...


如何在Typescript中组合多个属性装饰器?

我有一个带有属性 _id 的类模板,它具有来自 class-transformer 和 typed-graphql 的装饰器 从 'class-transformer' 导入 {classToPlain, Exclude, Expose, plainToClass, Type }; 重要...


IOS 不从快速 cookie 会话保存 cookie

这个问题一直让我抓狂。我在前端使用 React 和 Apollo (GraphQL),并在后端使用 Passport.js 和 Express cookie 会话进行身份验证。一切都很完美


React 作为 @vue/apollo-composable 的依赖项

我有一个使用 Composition API 的 VueJs 应用程序。我想使用 apollo 向我的 GraphQL 后端进行查询,但收到错误无法解析“react”。 我的依赖项是:“@...


EFCore 迁移是否应该致力于版本控制?

运行 dotnet ef migrations add XYZ 将导致在项目中创建 Migrations 目录。该目录是否应该提交版本控制(Git 等)?


graphql-spqr 在响应 json 中发送空值

我们已将 Spring Boot 应用程序配置为不以 json 形式发送回 null 值,但我们仍然会返回 null 值。使用 Jackson ObjectMapper 不发送空值的设置位于


dotnet core中的[ScriptIgnore]在哪里?

我正在将一个大型存储库转换为.net core,但我无法找到以前位于 System.Web.Script.Serialization 内部的 [ScriptIgnore] 属性的替代品。 有没有替代品...


Netflix dgs springboot UI http://localhost:8080/graphiql 不工作

尝试通过netflix-dgs实现graphql api。 获取资源未找到错误。 下面分享代码片段 出现以下错误 此应用程序没有 /error 的显式映射,因此您...


Shopify graphql 通过句柄获取文章?

有没有办法获得shopify博客文章的句柄?我说的是人类可读的 ID/句柄。似乎这个存在于液体侧,但不知道为什么它不存在于图表上......


GraphQL Spring Boot 中使用 @BatchMapping 的参数

在带有 BatchMapping 的 Java Spring Boot 中,我想知道如何访问参数。以下是该架构的部分内容: 类型查询{ 用户(用户名:字符串!):用户 } 类型用户{ 用户名:字符串!...


为什么代码中没有返回这个模拟值

我有一个 dotnet core 6 函数,包含以下几行 var csv = new CsvReader(阅读器, 配置)) var 记录 = csv.GetRecords().ToList(); 我设置模拟来模拟某些对象......


使用主键的Hasura where子句与特定主键查询

我在我的 postgres 数据库上使用 Hasura Graphql api。 我想使用主键从表中获取一行,但似乎有 2 种方法可以使用 Hasura 执行此操作,我正在尝试...


如何编写类型安全的函数签名来接受 amplify-js v6 graphql 订阅通知的回调函数?

使用版本 6.0.9 的 NPM 库 aws-amplify (不是 5.x.x!),我尝试将调用包装到 client.graphql({ query: typedGqlString, Variables}).subscribe({ next, error }),这样我就可以治疗...


GRPC 负载均衡和双工流媒体

我们使用 .NET 客户端进行 GRPC:https://github.com/grpc/grpc-dotnet 我们使用 DuplexStream 因为许多消息可以来自客户端首先初始化的同一个通道。 我们如何


“变量输入包含未为输入对象类型“DeleteNoteInput”定义的字段”

我在 AWS 中遇到了 graphQL 问题。该错误消息表明我输入的输入类型值无效。这让我很困惑,因为我正在从列表中获取该项目。那我...


maui android 应用程序在管道中构建失败,并出现错误“找不到 Android SDK 目录”

如果没有任何代码更改,Android 的管道构建将失败并出现以下错误。 /opt/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Linux/33.0.95/tools/Xamarin.Android.Tooling.targets(70...


如何将C# Gdal项目发布到Debian

我有一个使用 GDAL 和 GDAL.Native 包的 .NET Core C# Web 项目。一切在本地运行良好,但在发布到 Debian 服务器后,它会报告一堆消息,例如 /usr/share/dotnet/s...


如何使用 .NET TEST EXPLORER 在 VS Code 中运行 NUnit 测试

我想从 .NET TEST EXPLORER 运行单元测试,而不是命令行。我可以在导航到单元测试目录并执行 dotnet test 时运行测试。 但选择 .NET TEST EXPLORER...


如何使用 C# 开发套件在 Visual Studio Code 中设置 dotnet Release 配置构建?

我已经安装了 Visual Studio Code 和“C# Dev Kit”。看起来没有默认的方式让人们选择发布配置构建。 查看文档包,它提到了 a...


Azure Function App 无法启动 Docker 容器,原因是“Azure.RequestFailedException:指定的资源名称包含无效字符。”

我们有一个从 Docker 映像部署的 Azure Function 应用程序。 该函数正在运行 .NET 8.0,FUNCTIONS_EXTENSION_VERSION = ~4 且 FUNCTIONS_WORKER_RUNTIME = dotnet-isolated。 该应用程序包含...


发往 Azure 服务总线的消息会产生成功的请求,但队列中没有消息

我正在尝试在 DotNet 中实现后台服务,将消息发送到 Azure 服务总线中的队列。我的代码如下所示: 公共类 AuditBackgroundService :BackgroundService,


如何在expo react-native-app中收到FCM通知时禁用声音

我正在使用 firebase admin 从 dotnet 服务器发送通知来反应本机应用程序。在任何情况下一切都工作正常(前景、背景、死亡),但我希望用户能够


dotnet 工具在 Linux 中无法工作。您必须安装或更新 .NET 才能运行此应用程序。应用程序

这是我在电脑上安装的.NET 的信息。 点网--信息 .NET SDK: 版本:8.0.100 提交:57efcf1350 工作负载版本:8.0.100-manifests.6c33ef20 运行时环境...


使用 ASP.NET Core 和 TailwindCSS 进行热重载(或者:向 dotnet watch 添加额外的命令)

我正在研究将 TailwindCSS 与 ASP.NET 结合使用的良好热重载工作流程。 我决定使用 VSCode,因为 VisualStudio 没有良好的顺风扩展,而 Rider 的扩展也不支持...


我在.net 7.0中使用N层架构创建了一个项目。我的项目中还有API层和UI层。我想对我的项目进行 docker 化

`也就是说,在一个N层架构的有API层和UI层的项目中,dockerfile文件应该是什么样的? 来自 mcr.microsoft.com/dotnet/sdk:7.0 作为构建 工作目录/应用程序 复制./


MAUI 8 - 如何更改弹出背景叠加颜色?

使用 MAUI 7.0,下一个代码允许更改弹出背景叠加颜色,但该代码不适用于 MAUI 8.0 使用 MAUI 7.0,下一个代码允许更改弹出窗口背景覆盖颜色,但该代码不适用于 MAUI 8.0 <maui:MauiWinUIApplication x:Class="TestMaui8.WinUI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:maui="using:Microsoft.Maui" xmlns:local="using:TestMaui8.WinUI"> <maui:MauiWinUIApplication.Resources> <Color x:Key="SystemAltMediumColor">Transparent</Color> <SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="{StaticResource SystemAltMediumColor}" /> <SolidColorBrush x:Key="ContentDialogBackgroundThemeBrush" Color="{StaticResource SystemAltMediumColor}" /> <SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="{StaticResource SystemAltMediumColor}" /> <StaticResource x:Key="ContentDialogBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" /> <StaticResource x:Key="PopupLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" /> <SolidColorBrush x:Key="SliderBorderBrush" Color="#1A73E8" /> <Style TargetType="Slider"> <Setter Property="BorderBrush" Value="{StaticResource SliderBorderBrush}"/> </Style> </maui:MauiWinUIApplication.Resources> </maui:MauiWinUIApplication> 有人知道为什么它不起作用以及如何修复它吗? 更新添加一些图片 CommunityToolkit Popup 没有 Overlay color 功能。您可以在 CommunityToolkit GitHub 页面上提出功能请求。 是的,您发布的上述代码曾经可以工作,但它不适用于具有最新 CommunityToolkit.Maui nuget 的 .NET8。 但是如果您想更改叠加颜色,这里有一个解决方法。 <toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" ... Color="Black" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" > //make the size to be the full screen size <ContentView WidthRequest="1920" HeightRequest="1080"> <VerticalStackLayout WidthRequest="300" HeightRequest="300" BackgroundColor="Green"> <Image Source="dotnet_bot.png"/> <Label Text="Welcome to .NET MAUI!" VerticalOptions="Center" HorizontalOptions="Center" /> </VerticalStackLayout> </ContentView> </toolkit:Popup>


.NET MAUI、ios UseSafeArea 不工作 StackLayout、VerticalStackLayout 和 Grid

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Views.Activities.ActivityMapList" xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps" xmlns:sensors="clr-namespace:Microsoft.Maui.Devices.Sensors;assembly=Microsoft.Maui.Essentials" xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls" ios:Page.UseSafeArea="False" Shell.NavBarIsVisible="False" Style="{StaticResource Key=DefaultPage}"> <ContentPage.Content> <StackLayout> <maps:Map VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <x:Arguments> <MapSpan> <x:Arguments> <sensors:Location> <x:Arguments> <x:Double>36.9628066</x:Double> <x:Double>-122.0194722</x:Double> </x:Arguments> </sensors:Location> <x:Double>0.01</x:Double> <x:Double>0.01</x:Double> </x:Arguments> </MapSpan> </x:Arguments> </maps:Map> </StackLayout> </ContentPage.Content> </ContentPage> StackLayout 或 Grid 内的地图控件,iOS 的 SafeArea 为 false,如图所示。 你有什么解决办法吗? 我需要在地图上使用网格或堆栈布局 默认情况下.NET MAUI 将考虑安全区域。所以使用特定于平台的UseSafeArea就是禁用安全区域。目前,将 UseSafeArea 设置为 false 不会改变行为(尽管应该如此),这是一个错误。另请参阅 MAUI github 上的问题:https://github.com/dotnet/maui/issues/5856 您还可以设置 IgnoreSafeArea 属性来实现相同的目的。但是,它不再在 .NET 7 中工作,请参阅以下问题:https://github.com/dotnet/maui/issues/12823 要解决您的问题,您需要将 IgnoreSafeArea="True" 添加到您的 Grid 或 StackLayout 并将 ios:Page.UseSafeArea="False" 添加到您的页面。这应该不是必需的,但这是对我有用的解决方法。 有关在 iOS 上禁用安全区域的文档可以在此处找到:https://learn.microsoft.com/en-us/dotnet/maui/ios/platform-specifics/page-safe-area-layout?view=net-毛伊岛-7.0 您可以设置 Page Padding 值来实现。在OnAppearing方法中,设置页面的safeInsets,如下代码: protected override void OnAppearing() { base.OnAppearing(); DeviceSafeInsetsService d = new DeviceSafeInsetsService(); double topArea = d.GetSafeAreaTop(); double bottomArea = d.GetSafeAreaBottom(); var safeInsets = On<iOS>().SafeAreaInsets(); safeInsets.Top = -topArea; safeInsets.Bottom = -bottomArea; Padding = safeInsets; } 要获取 topArea 和 bottomArea 值,您应该编写平台代码。答案末尾附有有关此内容的更详细教程。 首先你可以在Project文件夹中生成一个新的类文件并将其更改为部分类。生成两个部分方法。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaTop(); public partial double GetSafeAreaBottom(); } 然后在iOS平台生成部分文件并实现。该文件位于 Project/Platform/iOS 文件夹中,我想提一下的是,该文件是一个部分文件,因此命名空间应与上面的文件相同。生成此文件时,请删除命名空间中的 .Platforms.iOS 后缀。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaBottom() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var bottomPadding = window.SafeAreaInsets.Bottom; return bottomPadding; } return 0; } public partial double GetSafeAreaTop() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var TopPadding = window.SafeAreaInsets.Top; return TopPadding; } return 0; } } 更多信息,您可以参考如何在.NET MAUI中编写特定于平台的代码和MauiPlatformCode示例代码 希望它对你有用。


棱镜:ViewModelLocator.AutowireViewModel 不适用于内容视图

我正在将使用 Prism 的 Xamarin.Forms 应用程序迁移到 .NET Maui。该应用程序有一个 TabbedPage 导航。此迁移有效。 但是 ContentPages 包含几个 ContentView,如下所示: 我正在将使用 Prism 的 Xamarin.Forms 应用程序迁移到 .NET Maui。该应用程序有一个 TabbedPage 导航。此迁移有效。 但是 ContentPages 包含几个 ContentView,如下所示: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:MauiDemo.Views" x:Class="MauiDemo.Views.HomePage" Title="HomePage"> <VerticalStackLayout> <views:FirstContentView HeightRequest="200"/> <views:SecondContentView HeightRequest="200"/> </VerticalStackLayout> </ContentPage> 在 Xamarin 中,我能够将 prism:ViewModelLocator.Autowire="true" 属性添加到 contentview 中,并且 prism 找到了关联的视图模型。在 .NET maui 中,prism:ViewModelLocator.AutowireViewModel="Automatic" 属性没有任何作用。 例如,ContentView 的名称是 “FirstContentView”。关联的viewModel的名称是“FirstContentViewViewModel” 根据https://prismlibrary.com/docs/maui/migration.html中的描述,它应该可以工作,但事实并非如此。 配置这样的自动接线有什么技巧吗? 我使用 prism 存储库的当前克隆 https://github.com/PrismLibrary/Prism 以及带有最新 MAUI 组件的当前 .NET8 SDK 我使用区域而不是通过自动装配。具有不同 ContentView 的页面应该如下所示 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:MauiDemo.Views" xmlns:prism="http://prismlibrary.com" x:Class="MauiDemo.Views.HomePage" Title="HomePage"> <VerticalStackLayout> <ContentView prism:RegionManager.RegionName="FirstContent"/> <ContentView prism:RegionManager.RegionName="SecondContent"/> </VerticalStackLayout> </ContentPage> 所需的视图及其视图模型应在 MauiProgram 中注册为 RegisterForRegionNavigation container.RegisterForRegionNavigation<FirstContentView, FirstContentViewViewModel>(); container.RegisterForRegionNavigation<SecondContentView, SecondContentViewModel>(); .UsePrism(prism => { prism.RegisterTypes(container => { container.RegisterForNavigation<MainPage,MainPageViewModel>(); container.RegisterForNavigation<HomePage>(); container.RegisterForRegionNavigation<FirstContentView, FirstContentViewViewModel>(); container.RegisterForRegionNavigation<SecondContentView, SecondContentViewModel>(); }) .CreateWindow(navigationService => navigationService.CreateBuilder() .AddSegment<MainPage>() .NavigateAsync(HandleNavigationError)); }) 包含多个ContentView的页面的ViewModel应该为所需的ContentView调用RegionManager.RequestNavigate方法。 public class HomePageViewModel : ViewModelBase, IInitialize { private readonly IRegionManager _regionManager; public HomePageViewModel(IRegionManager regionManager) { _regionManager = regionManager; } public void Initialize(INavigationParameters parameters) { _regionManager.RequestNavigate("FirstContent", nameof(FirstContentView)); _regionManager.RequestNavigate("SecondContent", nameof(SecondContentView)); } } 仅此而已。它的工作原理如https://xamgirl.com/prism-regions-in-xamarin-forms/所述


.NET MAUI 中的 Shell 背景渐变

知道如何为 Shell 提供渐变背景吗? 我尝试在 Shell 背景上定义 LinearGradientBrush 但这不起作用。 知道如何为 Shell 提供渐变背景吗? 我尝试在 Shell 背景上定义 LinearGradientBrush,但这不起作用。 <?xml version="1.0" encoding="UTF-8" ?> <Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Shell.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Red" Offset="0.25" /> <GradientStop Color="Blue" Offset="0.75" /> <GradientStop Color="LimeGreen" Offset="1.0" /> </LinearGradientBrush> </Shell.Background> <FlyoutItem FlyoutDisplayOptions="AsMultipleItems"> <!-- FlyoutItem contents here --> </FlyoutItem> </Shell> 我已经确认这是为 Shell.Background 设置渐变时的已知问题,请参阅 Shell.Background - Gradient does not work #10445,您可以按照该线程进行操作。 幸运的是,您可以单独设置渐变背景。如果您有“外壳”弹出窗口,则可以为“外壳”弹出项目设置渐变背景: <Shell.FlyoutBackground> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Red" Offset="0.25" /> <GradientStop Color="Blue" Offset="0.75" /> <GradientStop Color="LimeGreen" Offset="1.0" /> </LinearGradientBrush> </Shell.FlyoutBackground> 另外,如果要将 ShellContent 背景设置为渐变背景,可以将渐变背景添加到 ContentPage 的背景属性中。 <ContentPage.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Red" Offset="0.25" /> <GradientStop Color="Blue" Offset="0.75" /> <GradientStop Color="LimeGreen" Offset="1.0" /> </LinearGradientBrush> </ContentPage.Background> 希望这有帮助!


如何将 XAML(或另一个 ContentView)作为子项传递给 ContentView

我正在尝试创建一个 ContentView,并在其中将子项作为 XAML 或(另一个内容视图)传递。我怎样才能做到这一点? 例如。: 我有一种观点说 Header.xaml 我正在尝试创建一个 ContentView,并在其中将子项作为 XAML 或(另一个内容视图)传递。我怎样才能做到这一点? 例如: 我有一种观点是 Header.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:strings="clr-namespace:Eurynote.Localization.Resources.en;assembly=Eurynote.Localization" x:Class="Eurynote.Core.Views.Common.EurynoteHeader"> <HorizontalStackLayout Spacing="10" VerticalOptions="Center"> <Image Source="brand_icon" WidthRequest="32" HeightRequest="30" /> <Label Text="Header" Margin="0,-3,0,0" /> </HorizontalStackLayout> </ContentView> 现在,在我的 MainPage.xaml 文件中,我可以将此视图称为 <common:Header /> 并且运行良好。 但是我如何将另一个控件传递到与子项相同的内容视图,例如按钮、标签等...或任何其他 ContentView,如下面两个示例所示。 <common:Header> <Button Text="Button" /> </common:Header> <common:Header> <common:AnotherView /> </common:Header> 我想确保只能传递单个内容,如Frame。 谢谢你!!! 首先,如果使用以下代码,ContentView的内容将被Button覆盖。 <common:Header> <Button Text="Button" /> </common:Header> 因此您无法从 xaml 中为 contentview 添加子项。但你可以在后面的代码中做到这一点。如: 在xaml中: <common:Header x:Name = "header"> 在页面的构造函数中: public partial class MainPage() { InitializeComponent(); var layout = head.Content as HorizontalStackLayout; layout.Children.Add(new Button(){ Text = "new button"}); } 您可以通过这种方式将新项目作为子项添加到内容视图中。


© www.soinside.com 2019 - 2024. All rights reserved.