小编OXO*_*OXO的帖子

使用参数将依赖项注入到 ContentView(代码隐藏)中

在我的 .NET MAUI MauiProgram.cs 中,我注册了一个 ResourceManager 以及名为 MyContentView 的 ContentView 的代码隐藏(指的是 MyContentView.xaml.cs):

来自 MauiProgram.cs 的部分

...
var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .UseLocalizationResourceManager(settings =>
    {
        settings.RestoreLatestCulture(true);
        settings.AddResource(AppResources.ResourceManager);
    })
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    });

builder.Services.AddTransient<MyItemInputControlView>();

builder.Services.AddTransient<MyContentPage>();
builder.Services.AddTransient<MyContentPageViewModel>(); 
Run Code Online (Sandbox Code Playgroud)

MyItemInputControlView.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:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:views="clr-namespace:MyApp.Pages.Views"
             xmlns:loc="clr-namespace:LocalizationResourceManager.Maui;assembly=LocalizationResourceManager.Maui"
             xmlns:viewModels="clr-namespace:MyApp.ViewModels"
             x:Class="MyApp.Pages.Views.MyItemInputControlView"
             x:Name="this">

        
    <StackLayout BindingContext="{x:Reference this}">
        <Grid Margin="20, 0, 20, 0">
            <Grid.Resources>
                <!--<Style TargetType="Entry">
                    <Setter Property="Padding" Value="2 1" />
                    <Setter Property="BorderBrush" Value="LightGray" />
                </Style>-->
            </Grid.Resources>
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" …
Run Code Online (Sandbox Code Playgroud)

maui contentview

5
推荐指数
1
解决办法
2069
查看次数

获得焦点时选择条目中的所有文本

在我的 .NET MAUI 应用程序中,我想在条目聚焦时选择整个文本,以便可以更快地进行输入,而无需删除初始输入。

因此,我添加了以下代码:

XAML

<Entry Text="{Binding Min, Mode=TwoWay}" Focused="Entry_Focused" />
Run Code Online (Sandbox Code Playgroud)

代码隐藏

private void Entry_Focused(object sender, FocusEventArgs e)
{
    var entry = sender as Entry;

    entry.CursorPosition = 0;
    entry.SelectionLength = entry.Text == null ? 0 : entry.Text.Length;
}
Run Code Online (Sandbox Code Playgroud)

在我的Pixel 5 - API 33 (Android 13.0 - API 33)模拟器中,当我用鼠标单击我的 Entry 时,它的行为就像这样。

在此输入图像描述

当我继续使用Tab(用户没有)时,它的行为正确,正如您在此处看到的那样

在此输入图像描述

解决此问题的正确方法是什么,以便当用户单击条目并设置焦点时它的行为类似于第二个屏幕截图?

maui

5
推荐指数
1
解决办法
1420
查看次数

VS 更新到 17.7.3 后无法连接到 Mac

我刚刚在 Windows PC 上安装了新的 Visual Studio 2022 Update 17.7.3。从那时起,我无法再与我的 Mac 配对来部署我的 .NET MAUI 应用程序。我收到以下错误消息:

无法安装工作负载“ios”。详细信息:工作负载安装期间出错:在版本 16.4.7098 中安装清单“microsoft.net.sdk.ios”时出错:文件“microsoft.net.sdk.ios.manifest-7.0.100::16.4.7098”不是在 NuGet 源“https://api.nuget.org/v3/index.json; https://api.nuget.org/v3/index.json”中找到。

visual-studio maui

5
推荐指数
1
解决办法
847
查看次数

更改条目下划线的颜色或删除该颜色

在我的 .NET MAUI 条目中,我想更改代码隐藏中条目中下划线的颜色。

有没有办法做到这一点?

在此输入图像描述

======= 编辑并实施下面的答案 ======

提示:我使用自己的 BorderlessEntryControl 尝试了下面的答案,该控件派生自 Entry Control。在那里,至少 Placehodler-TextColor 丢失了。也许还有更多属性

在此输入图像描述

在此输入图像描述

maui

2
推荐指数
1
解决办法
6016
查看次数

标签 统计

maui ×4

contentview ×1

visual-studio ×1