WP7设置Datepicker边框颜色

时间:2011-02-04 00:48:10

标签: silverlight xaml windows-phone-7 silverlight-toolkit

我在工具箱Datepicker中设置边框颜色时遇到问题,因为它出现在页面上。我不是在谈论DatePickerPage。我可以设置背景和前景色,但边框不会占用。

<toolkit:DatePicker x:Name="dpDeliverBy" Header="Deliver By" Grid.Row="6" 
HeaderTemplate="{StaticResource MyHeaderTemplate}" Margin="-12, 0, 0, -10" Value=""
BorderBrush="Black" Background="White" BorderThickness="2" Foreground="Black" />

边界似乎没有抓住,我不知道还有什么其他财产可供使用。

2 个答案:

答案 0 :(得分:6)

您无法编辑DatePicker模板,这是一件有趣的事情。我通过查看由于某种原因发生的source code而发现,因为模板是在主控制主题中定义的 - Generic.xaml并且它本身没有定义BorderBrush属性。

下载软件包 - 您将需要它来在现有框架之上构建自定义控件。

您应该打开该主题文件,如果您要查看DatePicker的模板,则可以编辑BorderBrushBorderThickness的值。需要记住的一件事 - 一旦重新编译源代码,就需要确保使用正确的库(在主项目中引用时)。默认情况下,当您添加 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>

答案 1 :(得分:4)

没有必要重建Silverlight Toolkit没有必要达到预期的效果。 Toolkit采用的方法与XAML开始时使用的方法相同:“无视”控件。控件的逻辑在类文件中定义,可视外观在Themes \ generic.xaml文件的XAML中定义。

框架使用此文件中的XAML呈现控件,除非您指定替换,这是常见的事情。因此,您需要做的就是在App.xaml中添加新样式,然后您不需要重新编译Toolkit程序集,因为框架将使用您的自定义样式而不是新样式。

如果您想了解更多内容,VSJ上有一篇很好的文章可以解释这个模型。