簡體   English   中英

WPF組合框如何在LIST集合中顯示值

[英]WPF Combobox how to display value in LIST Collection

我有一個列表集合,當它被分配時,它具有短數字類型的集合。 但是,如何在WPF組合框上顯示數字?

我通常在XAML中使用DisplayMemberPath屬性,但是我不能聲明一個屬性,因為它不是我自己的集合。 (例如List(T)....)

XAML

<ComboBox HorizontalAlignment="Left" 
     ItemsSource="{Binding TheList}"
     // This is wrong of course
     DisplayMemberPath="." 

C#

public List<short> TheList
{
   get
   {
      return m_ListSID;
   }
   set
   {
      m_ListSID = value;
   }
 }

任何幫助將不勝感激。

編輯

完全愚蠢...所有答案當然都是正確的並且有意義,這僅僅是由於我忘記觸發集合的更新源

ItemsSource="{Binding TheList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

道歉

謝謝

在這里不需要DisplayMemberPath

<ComboBox HorizontalAlignment="Left"  ItemsSource="{Binding TheList}" DisplayMemberPath="" />

您不需要任何DisplayMemberPath
這足夠了:

<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding TheList}"/>

完全不要設置DisplayMemberPath ,應該將short轉換為string

<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding TheList}"/>

如果默認情況下沒有提供模板,則WPF將在項目上調用ToString()

編輯

您可以在ContentPresenter MSDN頁面上找到有關如何創建顯示內容的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM