wpf - 客户 WPF 日期选择器样式会中断所选日期
问题描述
我正在尝试使用 WPF 日期选择器并使整个控件更大。类似的过程适用于日历弹出窗口,但由于某种原因,当为日期选择器这样做时,所选日期永远不会改变。有没有办法扩大日期选择器的所有组件?
页面控制:
<DatePicker Grid.Column="0" SelectedDateFormat="Short" x:Name="StartDate"
CalendarStyle="{StaticResource resizedCalendarItem}" Style="{StaticResource resizedCalendarButton}" />
样式:
<Style x:Key="resizedCalendarButton" TargetType="{x:Type DatePicker}" BasedOn="{StaticResource {x:Type DatePicker}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePicker}">
<Viewbox HorizontalAlignment="Center" Width="150">
<DatePicker SelectedDate="{TemplateBinding SelectedDate}" />
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
解决方案
将 替换为绑定到实际TemplateBinding
的双向绑定:SelectedDate
DatePicker
<ControlTemplate TargetType="{x:Type DatePicker}">
<Viewbox HorizontalAlignment="Center" Width="150">
<DatePicker SelectedDate="{Binding SelectedDate,
RelativeSource={RelativeSource AncestorType=DatePicker}}" />
</Viewbox>
</ControlTemplate>
推荐阅读
- javascript - 添加了返回承诺,但随后不执行
- javascript - 使用蹦床编写阿克曼函数
- javascript - 构建确认网关功能
- python - 计算每个品牌的客户数量
- arrays - Kotin 类型不匹配:推断类型是 Int?但预计 Int
- c# - ListBox 中的 WPF 复选框:内容绑定未正确更新(即使已实现 INotifyPropertyChanged)
- google-apps-script - 使用 .getBackgrounds() 将背景颜色复制到范围
- javascript - 如何从一堆计算值中一个一个地分配 Vue 对象的属性?
- c# - 向 EventSource 中的所有 ETW 事件添加字段
- java - 如何对 API 响应进行分组和排序