xamarin - 在 xamarin 表单中更改 Windows.UI.Xaml.Controls.DatePicker 弹出窗口的 FontSize
问题描述
我的 xamarin 表单项目中有一个自定义渲染器来编辑 UWP 的 DatePicker 的样式。我已经修复了大小问题,现在我只是在单击 datepicker 以更新日期时尝试在 datePicker 弹出窗口中编辑文本的字体大小。这就是我的意思:
我目前有以下自定义渲染器代码来更改基本 datePicker 条目控件的中间宽度和字体大小,因此它看起来像
这是渲染器代码:
class MyDatePickerRenderer : DatePickerRenderer
{
#region Parent override
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
return;
if (Control != null)
{
Control.MinWidth = 150;
}
if (Element != null)
{
Element.FontSize = 12;
}
}
#endregion
}
关于如何更改 datePicker 弹出窗口的字体大小的任何想法?
解决方案
要更改弹出视图的字体大小,您可以参考这个案例。弹出视图的控制是LoopingSelector
。默认字体大小为 15,LoopingSelector
样式如下。
<Style TargetType="LoopingSelector">
<Setter Property="ShouldLoop" Value="True" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel VerticalAlignment="Center">
<TextBlock Text="{Binding PrimaryText}" FontFamily="{ThemeResource ContentControlThemeFontFamily}" FontSize="15" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Control">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="UpButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DownButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="ScrollViewer"
VerticalSnapPointsType="Mandatory"
VerticalSnapPointsAlignment="Near"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollMode="Disabled"
ZoomMode="Disabled"
Template="{StaticResource ScrollViewerScrollBarlessTemplate}" />
<RepeatButton x:Name="UpButton"
Content=""
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="8"
Height="22"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Visibility="Collapsed"
Style="{StaticResource DateTimePickerFlyoutButtonStyle}"
Background="{ThemeResource LoopingSelectorButtonBackground}"
IsTabStop="False" />
<RepeatButton x:Name="DownButton"
Content=""
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="8"
Height="22"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Visibility="Collapsed"
Style="{StaticResource DateTimePickerFlyoutButtonStyle}"
Background="{ThemeResource LoopingSelectorButtonBackground}"
IsTabStop="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果你想改变它。您只需将以下字体大小修改为另一个值。然后将完整的样式放在<Application.Resources>
xamarin uwp 项目中的 App.xaml 文件中。
<TextBlock Text="{Binding PrimaryText}" FontFamily="{ThemeResource ContentControlThemeFontFamily}" FontSize="20" />
推荐阅读
- java - 为什么即使邮箱中有邮件,JavaMail 也不列出邮件?
- javascript - 获取可细化字符串的内部 id
- ios - Ionic cordova-plugin-contacts 未安装,但他是。Xcode 10
- python - Python:返回值和返回无
- javascript - 显示为字符串的 HTML 标记
- javascript - 如何优化 60fps 模拟器的画布性能?
- python - Seleium 无法通过 mod_wsgi 在 Apache 上启动 Chrome 浏览器
- javascript - 如何添加“或”条件
- sql - 使用同一表中另一行的值设置行中的值
- javascript - HTML5 拖放 - 仅在每个拖放区的项目上