我正在try 在.NET Maui中构建一个自定义的Datepicker,但我有一些问题需要解决. 首先,DatePicker应该是这样的:

enter image description here

主要的问题是,我想要点击标签上的" Select 日期"打开日历进行日期 Select .因此,换句话说,我想通过单击标签来触发对DatePicker控件的虚假单击. 这是我的自定义控件的XAML代码:

<Grid xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="myProject.Custom_controls.CustomDatePicker"
             RowDefinitions="50"
             x:Name="this" >

    <!-- External rounded border -->
    <Border x:Name="borderDatePickerCustom" Grid.Row="0" Padding="8" StrokeShape="RoundRectangle 10,10,10,10" Stroke="{Binding Source = {x:Reference this}, Path = BorderColor}" 
            StrokeThickness="1">
        <Grid>

            <!-- DatePicker control -->
            <DatePicker x:Name="DatePickerCustom"
               Grid.Row="0"
               Margin="40,0,0,0"
               Format="{}{MM/dd/yyyy}"
               IsVisible="true"
               DateSelected="_OnDateSelected"
               Unfocused="_DatePickerUnfocused"/>

            <!-- Image control used to insert an icon left to the label -->
            <Image x:Name="DatePickerIcon"
            Grid.Row="0"
            VerticalOptions="Center"
            HorizontalOptions="Start"
            Margin="4"
            Source="calendar.png"
            IsVisible="true" />

        </Grid>
    </Border>

    <!-- Label used like placeholder -->
    <Label x:Name="lblPlaceholder"
           IsVisible="true"
           Grid.Row="0"
           FontSize="15"
           InputTransparent="true"
           Margin="50,0,10,0"
           Text="{Binding Source={x:Reference this}, Path=Text}"
           HorizontalOptions="StartAndExpand"
           VerticalOptions="CenterAndExpand"
           TextColor="{Binding Source={x:Reference this}, Path=PlaceholderTextColor}"
           BackgroundColor="{Binding Source={x:Reference this}, Path=PlaceholderBackgroundColor}"
           IsEnabled="{Binding Source={x:Reference this}, Path=IsEnabledCustom}">
    </Label>

    <!-- ImageButton used to erase datePicker content -->
    <ImageButton x:Name="EraseBtn"
                 Grid.Row="0"
                 VerticalOptions="CenterAndExpand"
                 HorizontalOptions="End"
                 Source="cross.png"
                 Margin="18"
                 IsVisible="false"
                 Clicked="_EraseDatePickerBtnClick" />
</Grid>

有谁知道能帮我的方法吗?这个应用程序应该主要工作在Windows平台上.

第二个问题是,我试图从DatePicker控件中删除日历标志符号,但没有成功

我试着在后台代码中将标签设置为inputTransparent = true,但不起作用.我也试着触发datePicker.Focus(),但也没有起作用. 我没有其他 idea ,我看到Android上存在PerformClick(),但我在Windows平台上.

推荐答案

要在不使用Focus()方法的情况下解决我的问题,我只需设置DatePickerOpacity = 0和标签ZIndex = -1,这样单击标签就可以打开DatePicker的弹出按钮.等待错误被修复.

Csharp相关问答推荐

当前文化和当前文化之间没有区别IgnoreCase,为什么?

单元测试和MOQ,最佳解决方案

Unity如何在PlayerPrefs中保存数据?

如何创建ASP.NET Core主机并在同一进程中运行请求

如何使用C#Interop EXCEL创建度量衡

Nuget包Serilog.Sinks.AwsCloudwatch引发TypeLoadExceptions,因为父类型是密封的

ASP.NET核心REST API返回一个非常大的数字

如何使用新的Microsoft.IdentityModel.JsonWebToken创建JwtSecurityToken?

UWP中的任务和界面

C#DateTime.ParseExact不使用特定日期

Selify只更改第一个下拉菜单,然后忽略REST-C#

使用ExtractIconEx(或其他方式)提取最大的可用图标

如果是,我怎么才能让这个加75,如果不是,我怎么才能减go 100?

委托RequestDelegate不带2个参数-ASP.NET Core 8最小API

在C#中过滤Excel文件

当使用Dapper映射DBNull时,我可以抛出异常吗?

MSTest--将消息直接写入StdOut和使用TestContext有什么不同?

Maui:更改代码中的绑定字符串不会更新UI,除非重新生成字符串(MVVM)

如何在ASP.NET Core 8中获取键控服务词典

与另一个对象位于同一位置的对象具有不同的变换位置