我实现了一个简单的 Shell 导航(伪代码):
Home -> GoToAsync Page1 -> GoToAsync Page2 -> backward navigate to Home using GoToAsync("../../")
Run Code Online (Sandbox Code Playgroud)
在最后一步中,我传递在 Page1 和 Page2 中收集的参数,以便 Home 中的方法 ApplyQueryAttributes() 第一次执行,并且我可以检索它们。
从那一刻起,用户可以沿着不同的路径移动:
Home -> GoToAsync Page3
Run Code Online (Sandbox Code Playgroud)
事实是:当使用 AppTitle 中的后退按钮或默认“返回”箭头从 Page3 导航回 Home 时,Home 中的方法 ApplyQueryAttributes() 始终执行,并且始终从 Page2 接收热门参数
这是一个 BUG 还是一个功能?
在我看来,这是一个 BUG,因为从 Page3 移动到 Home 时没有任何东西会将这些参数推送到 Home。这就像“回家”路线被缓存,当沿着这条路行驶时,“缓存”路线(带有 is 参数)被执行。
有什么办法可以防止这种行为吗?(无论是什么,错误还是功能)
我正在尝试通过 .NET Maui 制作一些绘图的东西。我已阅读文档,现在我可以通过命令绘制形状。但我不知道如何使用触摸事件(用手指绘图)来做到这一点。你知道我该怎么做吗?您知道这方面的任何指南或文档吗?我应该读什么?
我\xc2\xb4m 在 .net maui 中开发一个应用程序,我有一个问题,但我没有通过浏览回答自己。\n我正在尝试将阴影应用到边框,并且以下代码完美运行。
\n <Border \n Style="{StaticResource light-theme-border}"\n Grid.Column="1"\n Grid.Row="3"\n Grid.ColumnSpan="7">\n <Border.Shadow>\n <Shadow \n Brush="red"\n Offset="1,11"\n Radius="20"\n Opacity="0.25"/>\n </Border.Shadow>\n </Border>\nRun Code Online (Sandbox Code Playgroud)\n但是当我直接在边框属性内写入阴影时,它会捕获该属性,但我不知道如何转储[画笔、偏移、半径和不透明度]信息:
\n <Border \n Style="{StaticResource light-theme-border}"\n Grid.Column="1"\n Grid.Row="3"\n Grid.ColumnSpan="7"\n Shadow="???????????????????????????">\n </Border>\nRun Code Online (Sandbox Code Playgroud)\n 我有一个毛伊岛应用程序,想根据我所在的平台设计我的应用程序的样式。在资源字典中,我可以使用以下内容
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<OnPlatform x:Key="ButtonSize" x:TypeArguments="x:Double">
<On Platform="iOS" Value="14" />
<On Platform="Android" Value="16" />
</OnPlatform>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
Windows 和 Mac 的“平台字符串”是什么?
<On Platform="???" Value="16" />
Run Code Online (Sandbox Code Playgroud) 我正在尝试导航到“TestView”页面,该页面位于我的 VisualStudio 解决方案的“Views”文件夹中。这里编译错误。
错误 XFC0000 无法解析类型“:TestView”
AppShell.xaml 文件
<FlyoutItem Title="test" FlyoutIcon="List">
<ShellContent
Title="Test Page"
ContentTemplate="{DataTemplate local:TestView}"
Route="TestView" />
</FlyoutItem>
Run Code Online (Sandbox Code Playgroud)
需要帮助解决编译错误
更新:这是一个已确认的错误。请在这里投票,因为它并没有真正受到 MS 的太多关注。
我需要按照该指南重写加载应用内 HTML 内容shouldInterceptRequest的方法。WebViewClient
这是带有可重现代码的存储库:GitHub。我还从MS Q&A中获取了示例代码:
// ...
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Microsoft.Maui.Controls.WebView, ProblemHandler2>();
});
// ...
internal class ProblemHandler2 : WebViewHandler
{
protected override Android.Webkit.WebView CreatePlatformView()
{
var wv = new Android.Webkit.WebView(Android.App.Application.Context);
wv.SetWebViewClient(new CustomWebClient());
return wv;
}
}
Run Code Online (Sandbox Code Playgroud)
在存储库中,我包含了 2 个自定义处理程序:
ProblemHandler2这是 MSFT 的准确片段。我意识到一个问题:设置 MAUIWebView的Source属性不再导航真正的 Android WebView: WebViewHandler.Mapper.AppendToMapping("MyHandler", (handler, view) =>
{
#if ANDROID
var xWv = handler.PlatformView;
// For ProblemHandler2, this is …Run Code Online (Sandbox Code Playgroud) 我有一个使用 shell 弹出窗口的应用程序。当我添加弹出按钮时,它会自动创建一个图标,如下图所示:
但是,当我关闭 Android 深色主题时:
弹出图标仍然是白色的,因此很难看到:
我正在使用 AppThemeBinding 根据用户选择的系统主题自动相应地设置应用程序主题,但如果用户从 Android 设置中关闭深色主题,我不知道如何将弹出图标更改为更深的颜色。
知道该怎么做吗?
AppShell.xaml 当前如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MAUIApp1.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MAUIApp1"
FlyoutBackgroundColor="{AppThemeBinding Light=#f2f2f2, Dark=#2a2a2a}">
<Shell.Resources>
<ResourceDictionary>
...
</ResourceDictionary>
</Shell.Resources>
<Shell.FlyoutHeader>
...
</Shell.FlyoutHeader>
<Shell.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</Shell.ItemTemplate>
<FlyoutItem Title="Item1" Icon="item1.svg">
<ShellContent ContentTemplate="{DataTemplate local:page1}" Route="page1"/>
</FlyoutItem>
<FlyoutItem Title="Item2" Icon="item2.svg">
<ShellContent ContentTemplate="{DataTemplate local:page2}" Route="page2"/>
</FlyoutItem>
<FlyoutItem Title="Item3" Icon="item3.svg">
<ShellContent ContentTemplate="{DataTemplate local:page3}" Route="page3"/>
</FlyoutItem>
<Shell.FlyoutFooter>
...
</Shell.FlyoutFooter>
</Shell>
Run Code Online (Sandbox Code Playgroud) 当我使用 ContentLayout 将文本放在 ImageSource 下方时,如何调整图像大小。
<HorizontalStackLayout>
<Button MaximumHeightRequest="50"
Text="Open"
VerticalOptions="Start"
ImageSource="file_open.png"
ContentLayout="left,50" />
<Button Text="Open file test"
ContentLayout="Top,0"
VerticalOptions="Start"
ImageSource="file_open.png"
Command="{Binding DivideBy2Command}" />
<ImageButton x:Name="Toto"
MaximumHeightRequest="50"
VerticalOptions="Start"
Source="file_open.png"
Command="{Binding DivideBy2Command}" />
</HorizontalStackLayout>
Run Code Online (Sandbox Code Playgroud)
根据 ToolmakerSteve 和 Alexandar May(MSFT Stackoverflow 用户)的反馈以及使用 Padding,我能够得到我需要的东西。这里是更新的代码。
<HorizontalStackLayout>
<Button Text="Open"
HeightRequest="50"
VerticalOptions="Start"
ImageSource="file_open.png"
ContentLayout="left, 0"
/>
<Button
VerticalOptions="Start"
Text="Open File"
FontSize="10"
ImageSource="file_open.png"
ContentLayout="Top,-10"
Padding="2,-10,2,2"
HeightRequest="50"
WidthRequest="50"
/>
<ImageButton
VerticalOptions="Start"
Source="file_open.png"
MaximumHeightRequest="50"
/>
</HorizontalStackLayout>
Run Code Online (Sandbox Code Playgroud)
这里是输出
我已经完成了 .NET MAUI“创建 .NET MAUI 应用程序”启动教程。我对教程进行了一些修改,以使用 sqlite 数据库而不是 CollectionView 中每一行的文件。当他们在集合视图中编辑一行时,他们将该行的 DTO id 传递给新视图:
await Shell.Current.GoToAsync($"{nameof(NotePage)}?{nameof(NotePage.ItemId)}={SelectedNote.ID}");
Run Code Online (Sandbox Code Playgroud)
新视图使用以下注释加载 ItemID:
[QueryProperty(nameof(ItemId), nameof(ItemId))]
Run Code Online (Sandbox Code Playgroud)
然后,我使用该 ItemId 并对数据库进行另一次调用以返回 DTO,但由于我是从数据库加载数据,所以我已经从 CollectionView 中获得了 DTO,我只想将整个内容传递给新视图,如下所示某种查询参数来节省资源。我该怎么做呢?
我在网上看到有人提供了一个教程,显示可以这样通过:
await Shell.Current.GoToAsync(nameof(NotePage), SelectedNote);
Run Code Online (Sandbox Code Playgroud)
但是 Visual Studio 说我的第二个参数必须是 bool,所以我猜那些教程是错误的。
有人知道是否可以通过这种方式或类似的方式从视图传递 DTO?
谢谢,
在 .NET MAUI 中, aContentPage不具有该BarBackgroundColor属性,与NavigationPageand不同TabbedPage。是否有另一种方法可以更改导航栏颜色,例如Styles.xaml我不知道的属性?
maui ×10
xaml ×4
.net ×3
.net-maui ×3
c# ×3
android ×1
maui-windows ×1
navigation ×1
parameters ×1
query-string ×1
shadow ×1
shell ×1
webview ×1