【问题标题】:Change FontSize of Windows.UI.Xaml.Controls.DatePicker popup in xamarin forms在 xamarin 表单中更改 Windows.UI.Xaml.Controls.DatePicker 弹出窗口的 F​​ontSize
【发布时间】:2019-07-16 00:34:18
【问题描述】:

我的 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 弹出窗口的字体大小的任何想法?

【问题讨论】:

    标签: xamarin xamarin.forms uwp datepicker


    【解决方案1】:

    要更改弹出视图的字体大小,您可以参考case。弹出视图的控制是LoopingSelectorLoopingSelector 样式的默认字体大小为 15,如下所示。

    <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="&#xE70E;"
                    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="&#xE70D;"
                    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>
    

    如果你想改变它。您只需将以下字体大小修改为另一个值。然后在 xamarin uwp 项目中的 App.xaml 文件中的 &lt;Application.Resources&gt; 中放置完整的样式。

    <TextBlock Text="{Binding PrimaryText}" FontFamily="{ThemeResource ContentControlThemeFontFamily}" FontSize="20" />
    

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2022-01-09
      • 1970-01-01
      相关资源
      最近更新 更多