如何将弹出式日期选择器中的日期选择框的角进行圆角处理?

huangapple go评论58阅读模式
英文:

How to round the corners of the popup calendar in DatePicker?

问题

I need to change the design of the DatePicker component without creating a new element since I'm working on an application in Fluent design.

我需要在不创建新元素的情况下更改DatePicker组件的设计,因为我正在开发一个采用Fluent设计的应用程序。

I have already edited the default template of the DatePicker. I managed to change the design of the DatePicker's field and button. I was able to round the field and button corners. However, I couldn't modify the template of the popup calendar in the DatePicker. When editing the default DatePicker template, I didn't see the calendar there, although it should be present.

我已经编辑了DatePicker的默认模板。我成功地更改了DatePicker字段和按钮的设计。我能够将字段和按钮的角变为圆角。然而,我无法修改DatePicker中弹出式日历的模板。在编辑默认的DatePicker模板时,我没有看到日历,尽管它应该存在。

Is there a way to change the design of the popup calendar in DatePicker only by editing the default DatePicker template, without creating a new custom element?

是否有一种方法可以通过仅编辑默认的DatePicker模板来更改DatePicker中弹出式日历的设计,而不需要创建新的自定义元素?

英文:

I need to change the design of the DatePicker component without creating a new element since I'm working on an application in Fluent design.

I have already edited the default template of the DatePicker. I managed to change the design of the DatePicker's field and button. I was able to round the field and button corners. However, I couldn't modify the template of the popup calendar in the DatePicker. When editing the default DatePicker template, I didn't see the calendar there, although it should be present.

Is there a way to change the design of the popup calendar in DatePicker only by editing the default DatePicker template, without creating a new custom element?

Question in Screenshot

答案1

得分: 1

你可以添加Border并设置CornerRadius(以及在StackPanel上设置Margin,并将CalendarItemBackground设置为白色),但我不确定是否足够。
外观如何:带CornerRadius的DatePicker

完成方法如下:
使用此网站的资源和模板:
日历控件模板示例

像这样:<Window.Resources>许多代码...<Style x:Key="CalendarItemStyle" TargetType="{x:Type CalendarItem}">... 并像这样使用DatePicker

<DatePicker>
        <DatePicker.CalendarStyle>
            <Style TargetType="{x:Type Calendar}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Calendar}">
                            <Border
                                CornerRadius="10"
                                BorderThickness="1.5"
                                BorderBrush="Black"
                                >
                                <StackPanel x:Name="PART_Root"
                HorizontalAlignment="Center"
                                            Margin="1"
                >
                                    <CalendarItem x:Name="PART_CalendarItem"
                    Background="White"
                    Style="{TemplateBinding CalendarItemStyle}"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </DatePicker.CalendarStyle>
    </DatePicker>
英文:

You could add Border with CornerRadius (and Margin on StackPanel and for CalendarItem set Background to White), but I am not sure if it's enough.
How it looks: DatePicker with CornerRadius

How it's done:
Use Resources and Template from this site:
Calendar ControlTemplate Example

like this: <Window.Resources>a lot of code...<Style x:Key="CalendarItemStyle" TargetType="{x:Type CalendarItem}">... and use DatePicker like this:

<DatePicker>
        <DatePicker.CalendarStyle>
            <Style TargetType="{x:Type Calendar}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Calendar}">
                            <Border
                                CornerRadius="10"
                                BorderThickness="1.5"
                                BorderBrush="Black"
                                >
                                <StackPanel x:Name="PART_Root"
                HorizontalAlignment="Center"
                                            Margin="1"
                >
                                    <CalendarItem x:Name="PART_CalendarItem"
                    Background="White"
                    Style="{TemplateBinding CalendarItemStyle}"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </DatePicker.CalendarStyle>
    </DatePicker>

huangapple
  • 本文由 发表于 2023年7月3日 13:25:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定