如何增加CalendarDatePicker上选择的日期的字体大小

问题描述 投票:0回答:2

我的UWP应用程序上有CalendarDatePicker控件。我无法增加使用FontSize属性选择的日期字体的大小。

如果不覆盖很多样式,我怎么能轻松做到这一点?

这是我的基本代码:

<Page
    x:Class="CalendarPickerExample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CalendarPickerExample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <CalendarDatePicker FontSize="30" />
    </Grid>

</Page>

无论我在FontSize上设置CalendarDatePicker属性的大小,所选日期的字体大小都不会增加。

FontSize on CalendarDatePicker

请帮忙!

xaml datepicker uwp windows-10-universal
2个回答
1
投票

您可以使用Live Visual Tree工具检查控件的属性,在您要更改内部TextBlock的大小的情况下:

Live Visual Tree Live Property Explorer

您可以在默认样式https://msdn.microsoft.com/en-us/library/windows/apps/mt299110.aspx的副本中修改TextBlock字体大小

如您所见,它在默认模板中硬编码为15:

<TextBlock x:Name="DateText"
                   HorizontalAlignment="Left"
                   Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
                   Text="{TemplateBinding PlaceholderText}"
                   Grid.Row="1"
                   FontSize="15"
                   Padding="12, 0, 0, 2"
                   VerticalAlignment="Center" />

1
投票

您可以使用UWP Community Toolkit中的Visual Tree Extensions按名称或类型获取文本框控件并修改其FontSize属性:

 <CalendarDatePicker x:Name="Calender"/>

-

 Calender.FindDescendantByName("DateText").FontSize = 30;
© www.soinside.com 2019 - 2024. All rights reserved.