WPF設定DatePicker日期格式之卡Bug大法
阿新 • • 發佈:2022-03-14
<DatePicker Name="picker" Grid.Column="5" Grid.Row="0" SelectedDate="{Binding Patient.Birthday, StringFormat=yyyy-MM-dd, Converter={StaticResource DateConverter}}" VerticalAlignment="Center" SelectedDateChanged="DatePicker_SelectedDateChanged" BorderThickness="0" Style="{DynamicResource DatePickerStyle1}"> <DatePicker.Resources> <Style TargetType="DatePickerTextBox"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <TextBox x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, StringFormat={}{0:yyyy-MM-dd}, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </DatePicker.Resources> </DatePicker>
Style="{DynamicResource DatePickerStyle1}",標紅的樣式, 是不存在的。
試了半天,沒成功,無意中碰到了這個bug?哈哈