标签: maui

.Net MAUI 中单选按钮样式的问题

我在 .Net MAUI 中设置单选按钮样式时遇到了一些问题。最初,我注意到 Windows 和 Android 上的单选按钮外观并不一致,如下图所示:

单选按钮的外观

它们不仅不同,而且按钮样式的可用选项也很有限。定义颜色的唯一选项是“BorderColor”、“BackgroundColor”和“TextColor”。“BorderColor”和“BackgroundColor”对单选按钮本身的颜色完全没有影响。我想更改实际单选按钮的颜色。

所以我决定创建一个控制模板来帮助我。这是我的控件模板:

<ControlTemplate x:Key="RadioButtonTemplate">
    <Border Stroke="Transparent" BackgroundColor="Transparent">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroupList>
                <VisualStateGroup x:Name="CheckedStates">
                    <VisualState x:Name="Checked">
                        <VisualState.Setters>
                            <Setter TargetName="check" Property="Opacity" Value="1" />
                        </VisualState.Setters>
                    </VisualState>
                    <VisualState x:Name="Unchecked">
                        <VisualState.Setters>
                            <Setter TargetName="check" Property="Opacity" Value="0" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateGroupList>
        </VisualStateManager.VisualStateGroups>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid WidthRequest="20" HeightRequest="20" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Center">
                <Ellipse x:Name="border_circle" StrokeThickness="2" Stroke="DarkBlue" Fill="White" WidthRequest="18" HeightRequest="18" HorizontalOptions="Center" VerticalOptions="Center" />
                <Ellipse x:Name="check" Fill="DarkBlue" WidthRequest="10" HeightRequest="10" HorizontalOptions="Center" VerticalOptions="Center" />
            </Grid>
            <ContentPresenter Margin="10,0,0,0" Grid.Column="1" HorizontalOptions="Start" …
Run Code Online (Sandbox Code Playgroud)

xaml controltemplate radio-button maui

3
推荐指数
1
解决办法
3094
查看次数

.NET MAUI - “必须在主线程上调用权限请求”

我很困惑,如果需要异步,我应该如何在 Android 应用程序的主线程上请求权限访问。我想在我的应用程序打开后立即执行此操作,但我收到以下错误:"Permission request must be invoked on main thread."我该如何执行此操作?我的理解是,这RequestAsync需要一个单独的线程(因为它是一个异步方法调用)。

public partial class SplashPage : ContentPage
{
    PermissionStatus LocationPermission;

    public SplashPage()
    {
        InitializeComponent();
        LocationPermission = PermissionStatus.Unknown;
    }

    protected override void OnAppearing()
    {
        var result = Task.Run(async () => await CheckLocationPermission());
        result.Wait();
        var resultval = result.Result;

        result = Task.Run(async () => await RequestLocationPermission());
        result.Wait();
    }

    public async Task<PermissionStatus> CheckLocationPermission()
    {
        LocationPermission = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
        return LocationPermission;
    }

    public async Task<PermissionStatus> RequestLocationPermission()
    {
        try
        {
            if (LocationPermission == …
Run Code Online (Sandbox Code Playgroud)

c# android maui

3
推荐指数
1
解决办法
1834
查看次数

什么是 SemanticScreenReader.Announce(CalculateBtn.Text);

如果 VS 没有 bug 并且我的应用程序仍然可以工作,我可以在我的代码中删除它。我想了解这是做什么的,但我不能,因为我找不到解释。

我在网上查了一下找不到好的答案。

先感谢您。

.net maui

3
推荐指数
1
解决办法
2065
查看次数

如何解决 CommunityToolkit.Maui.MediaElement 中的安装问题

当我尝试安装 CommunityToolkit.Maui.MediaElement 时发生以下错误。如何解决该问题

严重性代码说明项目文件行抑制状态错误 NU1202 包 CommunityToolkit.Maui.MediaElement 1.0.1 与 net6.0-ios16.1 (.NETCoreApp,版本 = v6.0) 不兼容。软件包 CommunityToolkit.Maui.MediaElement 1.0.1 支持:

  • net7.0(.NETCoreApp,版本=v7.0)
  • net7.0-android33.0(.NETCoreApp,版本=v7.0)
  • net7.0-ios16.1(.NETCoreApp,版本=v7.0)
  • net7.0-maccatalyst16.1(.NETCoreApp,版本=v7.0)
  • net7.0-tizen7.0(.NETCoreApp,版本=v7.0)
  • net7.0-windows10.0.19041 (.NETCoreApp,版本=v7.0) MediaElement C:\Users\world\source\repos\MediaElement\MediaElement\MediaElement.csproj 1

xamarin maui

3
推荐指数
1
解决办法
1561
查看次数

.NET MAUI binding to GraphicsView

I have problems understanding how binding works in .NET MAUI. My goal is to have two ways of displaying a score inside a CollectionView, a label with the number and a graphical representation. The binding of the score to the label works just fine, but the binding to the Drawable does not. If I write a number instead of using a binding, it is passed just fine.

What am I doing wrong?

ProceduresPage.xaml

<?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" …
Run Code Online (Sandbox Code Playgroud)

c# data-binding maui

3
推荐指数
1
解决办法
1059
查看次数

如何在 MAUI 应用程序中设置要拉伸的线条长度?

我想在 MAUI 项目中使用一条线,这是文档:

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/shapes/line?view=net-maui-7.0

但我想在水平线上自动设置该线使用从左到右的所有空间。我没有看到像其他控件那样的拉伸选项。

我可以设置一个很长的长度,例如10000,但我想知道是否有更好的方法。

谢谢。

maui

3
推荐指数
1
解决办法
1081
查看次数

检查和请求毛伊岛权限(包括蓝牙)的简单方法?

我正在寻找一种简单的方法来查询和请求 .Net Maui 中的多个权限。我还需要请求蓝牙权限,但据我所知,毛伊岛没有内置的蓝牙权限。我在 2022 年最后一次听到的消息是,毛伊岛路线图中没有蓝牙,我觉得这是相当短视的。

我读了很多文章、问答、文档、观看了视频,并做了很多其他研究来解决这个问题。

到目前为止,我可以检查并请求个人权限,但我正在寻找比重复更干燥的东西:

PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.XXX>();

if (status != PermissionStatus.Granted){
    status = await Permissions.RequestAsync<Permissions.XXX>();
}
Run Code Online (Sandbox Code Playgroud)

对于每一个许可。我需要多个权限,因此我的检查很快就会失控。

顺便说一句,根据 Google Play 的要求,我的目标是 Android 13.0。

我知道这要求很高,但我迷失在所有建议中,其中许多建议不起作用,所以帮助解决所有这些问题就太好了!

c# permissions maui

3
推荐指数
1
解决办法
3669
查看次数

.NET MAUI 库:XamlC 错误 XFC0000:无法解析类型

当使用 Visual Studio 构建包含对 .NET MAUI Community Toolkit 的 IsEqualConverter引用的 .NET MAUI 库时,Visual Studio 输出窗口中会显示以下错误:

XamlC 错误 XFC0000:无法解析类型“http://schemas.microsoft.com/dotnet/2022/maui/toolkit:mct:IsEqualConverter”。

尝试在类库中使用其他 .NET MAUI Community Toolkit 转换器时也会出现此问题。

重现步骤

  1. 从 Visual Studio 中的重现存储库中打开解决方案。
  2. 尝试构建该项目。如果存在问题,XamlC error XFC0000: Cannot resolve type每个目标平台的 VS 输出窗口中都会报告错误。

链接到公共复制项目存储库

https://github.com/awalker-dsg/MauiLibTestLib_ConverterIssue

<?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="MauiLibTestLib_ConverterIssue.Views.IsEqualConverterPage"
             xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             Title="IsEqualConverterPage">
    <ContentPage.Resources>
        <x:String x:Key="MAUI">MAUI</x:String>
        <mct:IsEqualConverter x:Key="IsEqualConverter" />        
    </ContentPage.Resources>

    <!-- 
        The code in VerticalStackLayout was taken from the MAUI community toolkit sample code here:
        https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsEqualConverterPage.xaml
    -->
    <VerticalStackLayout Spacing="10">
        <Label Text="The …
Run Code Online (Sandbox Code Playgroud)

.net c# xaml maui maui-community-toolkit

3
推荐指数
1
解决办法
2791
查看次数

使用 Firebase 云消息传递的 .NET MAUI 推送通知

我想使用 Firebase Cloud Messaging 实现一个非常简单的推送通知系统。

MAUI 项目构建在 .NET 8 版本之上。

我已按照指南来设置项目。

指南使用 .net6 的地方我替换为 .net8

所以我的 .csproj 文件如下所示:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net8.0-android;net8.0-ios;</TargetFrameworks>
        <OutputType>Exe</OutputType>
        <RootNamespace>PushNotificationsTest</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

        <!-- Display name -->
        <ApplicationTitle>PushNotificationsTest</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.companyname.pushnotificationstest</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

        <!-- Images -->
        <MauiImage …
Run Code Online (Sandbox Code Playgroud)

.net c# maui

3
推荐指数
1
解决办法
1935
查看次数

iOS 17 中弃用了一堆 UIGraphics 方法,没有明确的替代方案?

我有一段使用 UIGraphics 方法的代码,似乎我使用的三种方法都已弃用。

这是一段 Xamarin.iOS 代码,但我相信 Swift 用户也可以在这里提供帮助,任何人都可以帮助我了解这些的新方法是什么,我正在尝试用 google 搜索,但我似乎没有得到任何信息关于这些方法的替代品的直接线索。

以下三种方法已被弃用;

    UIGraphics.BeginImageContextWithOptions(size, false, ScreenDensity);
    var image = UIGraphics.GetImageFromCurrentImageContext();
    UIGraphics.EndImageContext();
Run Code Online (Sandbox Code Playgroud)

完整的代码如下,不确定这是否有帮助......

private UIImage CreateBufferImage()
{
    if (paths is null || paths.Count == 0)
    {
        return null;
    }

    var size = Bounds.Size;
    UIGraphics.BeginImageContextWithOptions(size, false, ScreenDensity);
    var context = UIGraphics.GetCurrentContext();

    context.SetLineCap(CGLineCap.Round);
    context.SetLineJoin(CGLineJoin.Round);

    foreach (var path in paths)
    {
        context.SetStrokeColor(path.Color.CGColor);
        context.SetLineWidth(path.Width);

        context.AddPath(path.Path.CGPath);
        context.StrokePath();

        path.IsDirty = false;
    }

    var image = UIGraphics.GetImageFromCurrentImageContext();

    UIGraphics.EndImageContext();

    return image;
}
Run Code Online (Sandbox Code Playgroud)

谢谢

xamarin.ios ios xamarin swift maui

3
推荐指数
1
解决办法
1086
查看次数