代码之家  ›  专栏  ›  技术社区  ›  Anthony

更改wpf日期选择器的背景色

wpf
  •  0
  • Anthony  · 技术社区  · 5 年前

    我正在尝试更改wpf日期选择器的起始背景色

    现在看来: enter image description here

    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 回复  |  直到 5 年前
        1
  •  1
  •   mm8    5 年前

    可以通过添加隐式来更改文本框的背景。 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>