ItemsControl.ItemStringFormat 屬性

定義

取得或設定複合字串,這個字串會指定如何格式化 ItemsControl 中要以字串形式顯示的項目。

C#
[System.ComponentModel.Bindable(true)]
public string ItemStringFormat { get; set; }

屬性值

複合字串,指定如何格式化 ItemsControl 中要以字串形式顯示的項目。

屬性

範例

下列範例會使用 ItemStringFormat 指定 物件清單 DateTime 的格式。

XAML
<ListBox xmlns:sys="clr-namespace:System;assembly=mscorlib"
         ItemStringFormat="MMMM d, yyyy">
  <sys:DateTime>2004/3/4</sys:DateTime>
  <sys:DateTime>2004/8/9</sys:DateTime>
  <sys:DateTime>2005/10/14</sys:DateTime>
  <sys:DateTime>2005/4/8</sys:DateTime>
</ListBox>
  
  <!--The results when the default culture is en-US:
      March 4, 2004
      August 9, 2004
      October 14, 2005,
      April 8, 2005-->

備註

ItemStringFormat 可以是預先定義的、複合或自訂字串格式。 如需字串格式的詳細資訊,請參閱 格式化類型。 如果您設定 ItemTemplateItemsControlItemTemplateSelector ,則會 ItemStringFormat 忽略 屬性。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10