复选框内容中日期的字符串格式

String Format of Date in CheckBox Content

我有一个CheckBox想说的;

"Load Prior to: 01/01/2001"

但是内容却说;

"Load Prior to: 01 01 2001"

基本上没有斜杠。这是我设置内容的方式;

oldContactsCheckBox.Content = 
  "Load Contracts Prior To: " + 
   DateTime.Today.AddYears(-3).ToString("dd/MM/yyyy");

我怎样才能更改它以便在格式中包含斜线?

尝试转义:

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx#escape

oldContactsCheckBox.Content = 
  "Load Contracts Prior To: " + 
  DateTime.Today.AddYears(-3).ToString(@"dd\/MM\/yyyy");

更好的实现是字符串插值 (C# 6.0):

oldContactsCheckBox.Content = 
  $@"Load Contracts Prior To: {DateTime.Today.AddYears(-3):dd\/MM\/yyyy}";

格式化:

oldContactsCheckBox.Content = string.Format(
  @"Load Contracts Prior To: {0:dd\/MM\/yyyy}",
    DateTime.Today.AddYears(-3));