WP7 设置日期选择器边框颜色

发布于 2024-10-15 17:13:35 字数 388 浏览 4 评论 0原文

我在设置工具包日期选择器中出现在页面上的边框颜色时遇到问题。我不是在谈论 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" />

边界似乎没有固定下来,我不知道还有什么其他财产可以使用。

I'm having trouble setting the border color in a Toolkit Datepicker as it appears on a page. I'm not talking about the DatePickerPage. I can set the background and foreground colors, but the border doesn't take hold.

<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" />

The border doesn't seem to take hold and I don't know what other property to use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无需解释 2024-10-22 17:13:35

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

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

您应该打开该主题文件,如果查看 DatePicker 的模板,则可以编辑 BorderBrushBorderThickness 的值。要记住的一件事 - 一旦重新编译源代码,您需要确保使用正确的库(在主项目中引用时)。默认情况下,当您添加 Microsoft.Phone.Controls.Toolkit 单元时,它将引用在 GAC 中注册的库(假设您安装了该工具包)并采用位于 SDK 文件夹中的库-你不想要这样。更改库名称或更改本地副本。

如果您需要这方面的教程,我刚刚写了一个

下面是修改后的样式(在源码中修改,以便于复用):

<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>

It's an interesting thing that you cannot edit the DatePicker template. I found out by looking at the source code that for some reason it occurs because the template is defined in the main control theme - Generic.xaml and it has no BorderBrush property defined per se.

Download the package - you will need it to build a custom control on top of the existing skeleton.

You should open that theme file and if yo look at the template for DatePicker, you can edit the values for BorderBrush and BorderThickness. One thing to remember - once you re-compile the source, you need to make sure that you are using the correct library (when referencing in the main project). By default, when you add a Microsoft.Phone.Controls.Toolkit unit, it will reference the library registered in GAC (assuming that you installed the toolkit) and take the one that is located in the SDK folder - you don't want that. Either change the library name or change the local copy.

If you need a tutorial for this, I just wrote one.

Here is the modified style (modified in the source code for easier reuse):

<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>
戏舞 2024-10-22 17:13:35

没有必要重建Silverlight工具包来达到预期的效果。该工具包采用的方法与自 XAML 诞生以来一直使用的方法相同:“外观”控件。控件的逻辑在类文件中定义,视觉外观在 Themes\generic.xaml 文件的 XAML 中定义。

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

如果您愿意,VSJ 上有一篇很好的文章解释了此模型了解更多。

It isn't necessary to rebuild the Silverlight Toolkit isn't necessary to achieve the desired effect. The approach taken by the Toolkit is the same that has been used since XAML's inception: that of "lookless" controls. The control's logic is defined in the class file and the visual appearance is defined in XAML in the Themes\generic.xaml file.

The framework uses the XAML in this file render the control unless you specify a replacement, which is a common thing to do. So, all you need to do is to add the new style in App.xaml, and then you don't need to recompile the Toolkit assembly, because the framework will use your custom style instead of the new one.

There's a good article on VSJ that explains this model if you want to know more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文