有人可以帮助我解决我似乎无法解决的问题吗?我正在尝试通过在 Youtube 教程中找到的包 ZXing.Net.Maui 在 MAUI 中设置条形码扫描仪:https://www.youtube.com/watch ?v=ostgj2xB_ok&ab_channel=GeraldVersluis
我收到以下消息,表明 VS2022 无法识别 ZXing.Net.Maui 包,即使我安装了该包。
这些是 VS 2022 的错误
我已经导入了 ZXing 包,但 VS 似乎没有给我任何错误的红线
我找不到 ZXing.Net.Maui 包,但找到了一个似乎与其他包相关的不同包。我安装了 1.0.4,因为 1.0.5 版本已弃用。
有人能帮我吗?我需要使用这个包
问题是提前编译器给了我很多错误
我创建了一个新的、开箱即用的 .net MAUI 项目。我只是想查看 Android bud 的发布结果,但在运行发布版本时我立即收到错误。
配置中有一部分如下所示,表明不应运行 AOT:
`
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
<RunAOTCompilation>False</RunAOTCompilation>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
`
我想创建具有历史记录的计算器,并且需要在历史页面和计算页面之间共享数据。
我知道在 MAUI 页面之间共享数据的两种方法。
Shell.Current.GoToAsync();.txt文件并在类初始化时从中读取但就我而言,每次计算某些内容时,第一种方法都会重定向我,而第二种方法对我来说似乎有点臃肿。有没有更简单的方法来共享数据?
我正在尝试使用 FontAwesome 图标作为FlyoutItem图标FontImageSource。我通过以下设置在 Xamarin Forms 中取得了成功,但由于某种原因在 NET MAUI 中它不起作用(至少在 Windows 上?)?我看到选项卡项目,但无论我尝试什么,都没有图标。有没有办法使用 Font Awesome 图标而不是 png 图片?
我尝试使用的图标示例:https://fontawesome.com/icons/user?s =solid&f=classic
MauiProgram.cs:
var builder = MauiApp.CreateBuilder();
builder
.UseSkiaSharp(true)
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("FW-Regular-400.otf", "FontAwesomeRegular");
fonts.AddFont("FWBrands-Regular-400.otf", "FontAwesomeBrands");
fonts.AddFont("FW-Solid-900.otf", "FontAwesomeSolid");
});
Run Code Online (Sandbox Code Playgroud)
应用程序.xaml:
<!-- Desktop/Tablet-->
<FlyoutItem Title="Home">
<ShellContent ContentTemplate="{DataTemplate page:HomePage}">
<ShellContent.Icon>
<FontImageSource FontFamily="FontAwesomeSolid" Glyph=""/>
</ShellContent.Icon>
</ShellContent>
</FlyoutItem>
<FlyoutItem Title="Settings">
<ShellContent ContentTemplate="{DataTemplate page:SettingsPage}">
<ShellContent.Icon>
<FontImageSource FontFamily="FontAwesomeSolid" Glyph="user"/>
</ShellContent.Icon>
</ShellContent>
</FlyoutItem>
Run Code Online (Sandbox Code Playgroud)
我创建了一个虚拟毛伊岛应用程序。在跟踪应用程序信息后,我设法使用以下代码获取包名称
@page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
<ul>
<li>Name: @name</li>
<li>Package: @package</li>
<li>Version: @version</li>
<li>Build: @build</li>
</ul>
@code {
private string name = AppInfo.Current.Name;
private string package = AppInfo.Current.PackageName;
private string version = AppInfo.Current.VersionString;
private string build = AppInfo.Current.BuildString;
protected override async Task OnInitializedAsync()
{
}
}
Run Code Online (Sandbox Code Playgroud)
正如您从下图中看到的,这确实有效,它显示了我的 Android 应用程序信息。但 ...
我的问题是如何配置此包名称显示为 com.companyname.blazortest。我希望能够提供我的公司名称
没有 appsettings.json 文件,它不在 AndroidManifest.xml 中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" …Run Code Online (Sandbox Code Playgroud) 我已经从代码后面设置了 ViewModel 以进行依赖注入。我想在 xaml 中留下 IntelliSense 建议的可能性。一切似乎都有效,但是一旦添加x:DataType="viewModels:HomeViewModel",我就会收到属性未找到的错误Number,并且无法运行我的解决方案。为什么会这样以及如何解决这个问题?
如果我删除x:DataType="viewModels:HomeViewModel",一切正常。
主页.xaml:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Pages.HomePage"
xmlns:viewModels="clr-namespace:MyApp.ViewModels"
x:DataType="viewModels:HomeViewModel"
Title=""
NavigationPage.HasNavigationBar="False">
<Frame>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0"></Label>
<ListView ItemsSource="{Binding TotalData}" Grid.Row="1">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5">
<Label Text="{Binding Number}" Margin="0,0,10,0"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Frame>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
编辑:
根据杰森的回答,我HomePage.xaml应该是:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Pages.HomePage"
xmlns:viewModels="clr-namespace:MyApp.ViewModels"
xmlns:models="clr-namespace:MyApp.Models"
x:DataType="viewModels:HomeViewModel"
Title=""
NavigationPage.HasNavigationBar="False">
<Frame>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0"></Label>
<ListView ItemsSource="{Binding TotalData}" …Run Code Online (Sandbox Code Playgroud) 是否可以从 ViewModel 中的属性获取 control\xe2\x80\x99s 背景颜色?
\n目的是能够改变用户操作的颜色Border或Button基于用户操作的颜色。因为我\xe2\x80\x99m 使用 MVVM 方法,所以理想情况下,我只需通过视图模型中的属性设置控件的背景颜色。
我尝试了以下方法,但它没有 \xe2\x80\x99 工作:
\n<Border\n BackgroundColor="{Binding MyBorderBackgroundColor}">\n <Label Text=\xe2\x80\x9cHello World\xe2\x80\x9d />\n</Border>\nRun Code Online (Sandbox Code Playgroud)\n在我的视图模型中,我使用一个string属性并将其设置为颜色名称(例如)Red或十六进制值(例如)#FF0000。我有一个Init()调用的方法OnAppearing()并设置值的方法 - 见下文:
[ObservableProperty]\nstring myBorderBackgroundColor;\n \n...\n \npublic void Init()\n{\n MyBorderBackgroundColor = "Red"; // Or Hex value => MyBorderBackgroundColor = "#FF0000";\n}\nRun Code Online (Sandbox Code Playgroud)\n该应用程序只是忽略颜色设置并默认为页面背景。没有错误,但只是不使用通过视图模型属性设置的值。
\n有什么建议么?
\n我想知道如果绑定属性的布尔值为 false,是否或如何将 xaml 元素的 IsVisible 属性设置为 true?
根据布尔属性的值,我想有条件地在视图中渲染不同的元素。
这是我的代码:
<ContentPage ...
x:Name="page">
<ListView BindingContext="{x:Reference page}" ItemSource="digitalInputs">
<ListView.ItemTemplate>
<DataTemplate x:DataType="services:DigitalInput">
<ViewCell>
<HorizontalStackLayout>
<!-- This seems to be working. Render a green ball, if boolean value is true -->
<Image Source="ballgreen" IsVisible="{Binding value}"/>
<!-- Doesn't work. I want to render a red ball if the boolean value is false. -->
<Image Source="ballred" IsVisible="{Binding !value}"/>
<Label Text="{Binding valueText}" />
</HorizontalStackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
我考虑过向 DigitalInput 类添加另一个布尔属性,并将其值设置为 的相反值value,但另一方面,我不想触及该类,因为它以 1:1 的方式模拟我从 …
我正在尝试更改 MAUI 项目中的应用程序图标,但我无法做到这一点。
我已将两个图像添加到 AppIcon 文件夹(我尝试了 png 和 svg 但它们都不起作用)
并将 csproj 文件更改为新图标
<MauiIcon Include="Resources\AppIcon\coolcoicon.svg" ForegroundFile="Resources\AppIcon\coolcoiconbg.svg" Color="#000000" />
我已经清理了解决方案和项目。
但是,当我尝试在 Android 模拟器中播放该应用程序时,出现这些错误
Error APT2260 resource mipmap/appicon (aka com.coolco.coolcoapp:mipmap/appicon) not found.
Error APT2260 resource mipmap/appicon_round (aka com.coolco.coolcoapp:mipmap/appicon_round) not found.
Error APT2067 failed processing manifest.
Run Code Online (Sandbox Code Playgroud)
我正在尝试将我的 [Xamarin Forms with Prism] 应用程序移植到毛伊岛(也使用 Prism)。毛伊岛棱镜网页承诺包含一些示例,但到目前为止还没有(毛伊岛)。
任何人都可以分享任何资源的链接,描述如何使用Prism正确设置Maui吗?Prism 网站上描述了一些概念,但所附的示例只是几句话,没有涵盖我所遗漏的内容。