这是一个有趣的事情,你不能编辑DatePicker
模板。我通过查看source code发现,出于某种原因,它发生是因为模板在主控制主题中定义 - Generic.xaml
并且它本身没有定义BorderBrush
属性。
下载软件包 - 您将需要它在现有骨架上构建自定义控件。
您应该打开该主题文件,如果您查看DatePicker
的模板,则可以编辑BorderBrush
和BorderThickness
的值。有一点要记住 - 一旦你重新编译源代码,你需要确保你使用了正确的库(当在主项目中引用时)。默认情况下,当您添加一个Microsoft.Phone.Controls.Toolkit单元时,它将引用在GAC中注册的库(假设您安装了该工具包)并采用位于SDK文件夹中的库 - 您不需要想要那个。请更改库名称或更改本地副本。
如果你需要这个教程,I just wrote one。
下面是修改的样式(在源代码中修改的更容易再利用):
<Style TargetType="controls:DatePicker">
<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Azure"/>
<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="controls:DatePicker">
<StackPanel>
<ContentControl
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Foreground="{StaticResource PhoneSubtleBrush}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="12,0,12,-4"/>
<Button
x:Name="DateTimeButton"
Content="{TemplateBinding ValueString}"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"
Height="72"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这确实取决于 - 为了将来重复使用,保持属性打开并且能够在没有模板的情况下进行设置会更容易。 – 2011-02-04 16:03:25