2014-02-25 33 views
0

問題在WPF ComboBox項目:與收藏displayvaluepath WPF組合框綁定,SelectedValuePath不工作

XAML:

<ComboBox x:Name="cboSelectSeries" Width="100" Height="25" Grid.Row="3" 
      Grid.Column="3" SelectedIndex="0" 
      ItemsSource="{Binding}" SelectedValuePath="SeriesNumber" 
      DisplayMemberPath="NId" /> 

XAML.cs

internal List<NPIS.PortableObject.NPIS> NCollection; 
.. 
NCollection=getdata(); 
cboSelectSeries.DataContext = NCollection; 

輸出:

與項目作爲「NPIS.PortableObject.NPIS」

+0

其更好地設置的ItemSource你的情況...'cboSelectSeries.ItemsSource = NCollection;' – Sankarann

+0

我想,太.. – Habeeb

回答

0

我嘗試下面的代碼和它沒有工作。

public partial class MainWindow : Window 
{ 
    public List<PortableObject> NCollection; 

    public MainWindow() 
    { 
     InitializeComponent(); 

     NCollection = getdata(); 
     cboSelectSeries.DataContext = NCollection; 
    } 

    private List<PortableObject> getdata() 
    { 
     return new List<PortableObject> 
          { 
           new PortableObject 
            { 
             SeriesNumber = 001, 
             NId = 10, 
            }, 
            new PortableObject 
            { 
             SeriesNumber = 002, 
             NId = 20, 
            }, 
            new PortableObject 
            { 
             SeriesNumber = 003, 
             NId = 30, 
            }, 
          }; 
    } 
} 

public class PortableObject 
{ 
    public int SeriesNumber { get; set; } 
    public int NId { get; set; } 
} 
+0

我試着在樣品溶液我們的代碼它顯示的項目與「NID」,但當選擇某個項目時,它不顯示SeriesNumber。 請幫忙。 – Habeeb

+0

當您選擇一個項目時,該項目基本上是'PortableObject'對象,因此要獲取SeriesNumber,您需要具有另一個屬性,該屬性應該綁定ComboBox的SelectedItem屬性。 – rajibdotnet

0

我懷疑它找不到屬性路徑NId在類NPIS。確保你有公開暴露的財產在基礎類。另外路徑名是區分大小寫,請確保路徑名和屬性名是正確的。

public int NId { get; set; }