【问题标题】:Silverlight toolkit for WP7, DatePicker\TimePicker fontsize problemWP7 的 Silverlight 工具包,DatePicker\TimePicker 字体大小问题
【发布时间】:2014-04-29 18:39:55
【问题描述】:
我在使用 Silverlight Toolkit for WP7 的 TimePicker \ DatePicker 时遇到以下问题。我不知道如何在选取器内的 TextBox 中更改字体大小:
FontSize 属性:
<toolkit:DatePicker FontSize="30" Foreground="Black" Header="tas" Name="dpiker"/>
仅更改标题字体大小
虽然 FontFamily 或 FontWeight 适用于 Header 和 TextBox。如何更改文本框中的字体大小?
Here is the same question o silverlight forum
【问题讨论】:
标签:
silverlight
windows-phone-7
datepicker
font-size
toolkit
【解决方案1】:
这是因为在它们的默认样式中,字体大小不是通过 TemplateBinding 设置的。请参阅 ** 部分,这应该可以解决问题。 :)
<Style TargetType="toolkit:DatePicker">
<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="PickerPageUri" Value="/Microsoft.Phone.Controls.Toolkit;component/DateTimePickers/DatePickerPage.xaml"/>
<Setter Property="ValueStringFormat" Value="{}{0:d}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:DatePicker">
<StackPanel>
<ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{StaticResource PhoneSubtleBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="12,0,12,-4"/>
<Button x:Name="DateTimeButton" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Content="{TemplateBinding ValueString}" Foreground="{TemplateBinding Foreground}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Height="72" **FontSize="{TemplateBinding FontSize}"**/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
【解决方案2】:
基于 noxo 的 wordpress 链接,这对我来说效果很好:
<Style x:Key="DatePickerStyle1" TargetType="toolkit:DatePicker" BasedOn="{StaticResource DateTimePickerStyles}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:DatePicker">
<StackPanel>
<ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{StaticResource PhoneSubtleBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="12,0,12,-4"/>
<Button x:Name="DateTimeButton" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Content="{TemplateBinding ValueString}" Foreground="{TemplateBinding Foreground}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Height="Auto" FontSize="{TemplateBinding FontSize}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>