更改日期选择器的边框颜色
我想更改 DatePicker
控件上焦点状态的边框颜色。 我查看了默认样式模板,没有看到 VisualStateManager
的任何焦点状态。
我唯一看到的是 TextBox
的原始控件,如下所示:
<controlsPrimitives:DatePickerTextBox x:Name="TextBox" SelectionBackground="{TemplateBinding SelectionBackground}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Column="0" />
How can I change the color for the focus state for the border for the DatePicker... 我有更改 TextBox
、ComboBox
和 CheckBox
控件的颜色没有问题。
请帮忙!
I would like to change the border color for the focus state on the DatePicker
control.
I took a look at the Default Style Template and didn't see any Focus State for the VisualStateManager
.
The only thing I saw was a primitive control for the TextBox
as follows:
<controlsPrimitives:DatePickerTextBox x:Name="TextBox" SelectionBackground="{TemplateBinding SelectionBackground}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Column="0" />
How can I change the color for the focus state for the border for the DatePicker
... I had no problem changing this color for the TextBox
, ComboBox
and the CheckBox
controls.
Please Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是对的,
DatePicker
控件没有VisualStateManager
的焦点状态。请注意,可以为DatePicker
添加状态组和聚焦/不聚焦状态,但这不是最好的方法。的模板 DatePicker
控件包含DatePickerTextBox
控件,根据 MSDN,它“代表DatePicker
的文本输入”。查看
DatePickerTextBox
的模板,我们发现它有一个FocusStates
状态组,以及Unfocused
和Focused 的定义
状态。我们还找到了这一行:如您所见,默认的“聚焦颜色”是
# FF6DBDD1
。DatePickerTextBox
的Focused
状态将此边框的Opacity
属性设置为1
。要更改
Focused
状态的边框颜色,您可以创建此模板的副本,并将#FF6DBDD1
替换为您想要的颜色。然后,创建DatePicker
模板的副本,该副本应指定其中包含的DatePickerTextBox
应使用修改后的模板。或者,您可以创建
DatePickerTextBox
模板的副本,调整边框颜色,然后将此模板置于TargetType
设置为DatePickerTextBox< 的样式中。 /code>:
希望这对您有用!
编辑:
DatePickerTextBox
的默认模板大多数控件的默认样式和模板均可用 在 MSDN 上。但是(无论出于何种原因),
DatePickerTextBox
不是。如果您有 Expression Blend 的副本(如果您正在处理控件的外观,我强烈推荐它;它是无价的 - 下载免费试用版 此处),您可以执行以下操作:右键单击
DatePicker
,单击“编辑模板 -> 编辑副本...” ”。您将在“对象和时间轴”面板中看到DatePickerTextBox
。右键单击它,再次单击“编辑模板 -> 编辑副本...”。然后,您可以右键单击“对象和时间轴”面板中的模板,然后单击“查看 XAML”。再说一遍,如果您正在做任何类似的工作,我强烈推荐 Blend。从长远来看,它将为您节省大量时间(并且您将学到大量有关 XAML、样式、模板、它们如何组合在一起等的知识)。不过,如果您无权访问它,这里是
DatePickerTextBox
控件的默认模板:对于篇幅抱歉,非常感谢 此帖子(有同样的问题)。
You're right, the
DatePicker
control doesn't have a Focus state for theVisualStateManager
. Note that it is possible to add a state group and Focused/Unfocused states for theDatePicker
, but that wouldn't be the best approach here.The template for the
DatePicker
control contains aDatePickerTextBox
control, which, according to MSDN, "represents the text input of aDatePicker
".Looking at the template for the
DatePickerTextBox
, we find that it has aFocusStates
state group, and definitions for both theUnfocused
andFocused
states. We also find this line:So as you can see, the default "focused color" is
#FF6DBDD1
. TheFocused
state for theDatePickerTextBox
sets theOpacity
property of this border to1
.To change the border color for the
Focused
state, you can create a copy of this template, replacing#FF6DBDD1
with the color you want. Then, create a copy of theDatePicker
template, which should specify that theDatePickerTextBox
contained within it should use your modified template.Alternatively, you can create a copy of the
DatePickerTextBox
template, make the adjustment to the border color, and place this template in a style withTargetType
set toDatePickerTextBox
:Hopefully this is useful to you!
EDIT: Default Template for
DatePickerTextBox
Most of the default styles and templates for controls are available on MSDN. However (for whatever reason),
DatePickerTextBox
is not. If you have a copy of Expression Blend (which I highly recommend if you are working with the appearance of controls; it's invaluable -- download a free trial here), you can do the following:Right-click on a
DatePicker
, click "Edit Template -> Edit a Copy...". You'll see theDatePickerTextBox
in the "Objects and Timeline" panel. Right-click on that, click "Edit Template -> Edit a Copy..." once more. You can then right-click on the Template in the "Objects and Timeline" panel and click "View XAML."Again, if you're doing any sort of work like this, I can't recommend Blend highly enough. It will save you so much time in the long run (and you'll learn a ton about XAML, styles, templates, how they all fit together, etc). If you don't have access to it, though, here's the default template for the
DatePickerTextBox
control:Apologies for the length, and many thanks to this thread (which had the same issue).
这对你有用吗:
Does this work for you: