我正在try 在.NET Maui中构建一个自定义的Datepicker,但我有一些问题需要解决. 首先,DatePicker应该是这样的:
主要的问题是,我想要点击标签上的" 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平台上.