我正在尝试更改WPF日期选择器的起始背景颜色
XAML看起来像
<DatePicker SelectedDate="{Binding SelectedDate, RelativeSource={RelativeSource TemplatedParent}}"
Margin="4" Grid.Column="1" VerticalAlignment="Center"
Background="{TemplateBinding Background}">
<DatePicker.CalendarStyle>
<Style TargetType="{x:Type Calendar}">
<Setter Property="Background" Value="Black" />
</Style>
</DatePicker.CalendarStyle>
</DatePicker>
当前设置程序正在将日历下拉菜单设置为黑色。我想将当前背景设置为深色。
答案 0 :(得分:1)
您可以通过向DatePickerTextBox
添加隐式<DatePicker.Resources>
样式来更改文本框的背景:
<DatePicker Background="Black" Margin="4" Grid.Column="1" VerticalAlignment="Center">
<DatePicker.CalendarStyle>
<Style TargetType="{x:Type Calendar}">
<Setter Property="Background" Value="Black" />
</Style>
</DatePicker.CalendarStyle>
<DatePicker.Resources>
<Style TargetType="DatePickerTextBox">
<Setter Property="Background" Value="Silver" />
</Style>
</DatePicker.Resources>
</DatePicker>