.Net MAUI TimePicker resize in window platform

Ye Min Tun 1 Reputation point
2022-09-13T08:37:50.647+00:00

How to reduce the width of .Net MAUI TimePicker from default value of 242 in Window? I tried to reduce minWidth with TimePickerHandler, but it doesn't work. How can I deal with that? Do I need to create custom TimePicker?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,542 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,371 Reputation points Microsoft Vendor
    2022-09-14T02:39:01.247+00:00

    Hello,

    I tried to reduce minWidth with TimePickerHandler, but it doesn't work.

    It is caused by that the minimal size of each Cell in TimePicker is 80.

    You need to copy default style for TimePicker from this file C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\Generic\generic.xaml into Your_MAUI_Project\Platforms\Windows\App.xaml, such as the following code:

       <maui:MauiWinUIApplication  
           ...>  
           <maui:MauiWinUIApplication.Resources>  
               <!-- Default style for TimePicker --> from xaml file.  
           </maui:MauiWinUIApplication.Resources>  
       </maui:MauiWinUIApplication>  
    

    Then, you need to modify MinWidth="{StaticResource TimePickerThemeMinWidth}" to MinWidth="30.

    After that, you could find the TimePicker could be shown as expected.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.