2012-05-18 24 views
6

पर बांधें मुझे अपने डेटा को सही तरीके से बांधने में बड़ी मात्रा में परेशानी हो रही है। मैंने यहां इसी तरह के मुद्दों वाले लोगों से अधिकतर पोस्ट पढ़ी हैं, लेकिन किसी कारण से मैं इसे क्लिक करने के लिए नहीं मिल सकता।एक अवलोकन करने योग्य चयन को एक सूची दृश्य

मेरी मेज के लिए एक्सएमएल है:

<Window ... DataContext="{Binding RelativeSource={RelativeSource Self}}" > 
... 
<ListView Height="124" HorizontalAlignment="Left" Margin="12,46,0,0" Name="listViewDocuments" VerticalAlignment="Top" Width="Auto" DataContext="{Binding DocumentList}"> 
    <ListView.View> 
     <GridView> 
      <GridViewColumn Width="160" Header="Description" DisplayMemberBinding="{Binding Description}"/> 
      <GridViewColumn Width="160" Header="Date Filed" DisplayMemberBinding="{Binding DateFiled}"/> 
      <GridViewColumn Width="160" Header="Filed By" DisplayMemberBinding="{Binding UserFiledName}"/> 
      <GridViewColumn Width="150" Header="Page" DisplayMemberBinding="{Binding Pages}"/> 
      <GridViewColumn Width="150" Header="Notes" DisplayMemberBinding="{Binding Notes}"/> 
      <GridViewColumn Width="Auto" Header="" /> 
     </GridView> 
    </ListView.View> 
</ListView> 

मेरी कोड के भीतर मेरे पास है:

_DocumentList.Add(new Document 
{ 
    Description = dr["Description"].ToString(), 
    DateFiled = dr.GetDateTime(dr.GetOrdinal("DateFiled")).ToShortDateString(), 
    UserFiledName = dr["UserFiledName"].ToString(), 
    Pages = dr.GetInt32(dr.GetOrdinal("Pages")).ToString(), 
    Notes = dr["Notes"].ToString(), 
    Tag = dr["FileID"].ToString() 
}); 

नए आइटम:

public ObservableCollection<Document> _DocumentList = new ObservableCollection<Document>(); 

... 

public ObservableCollection<Document> DocumentList{ get { return _DocumentList; } } 

... 

public class Document 
{ 
    public string Description { get; set; } 
    public string DateFiled { get; set; } 
    public string UserFiledName { get; set; } 
    public string Pages { get; set; } 
    public string Notes { get; set; } 
    public string Tag { get; set; } 

} 

तालिका का उपयोग मैं अद्यतन करने की कोशिश में प्रतीत होता है कि सही ढंग से जोड़ा जा रहा है, लेकिन सूची दृश्य पर कुछ भी अपडेट नहीं किया गया है।

मैं इस तरह ट्यूटोरियल के माध्यम से पढ़ा है: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1

और मैं अधिसूचना कोड है कि अन्य पदों में सुझाव दिया है के सभी को जोड़ने की कोशिश की है। मेरे लिए कुछ भी काम नहीं कर रहा है।

और विचारों की सराहना की जाएगी।

+0

क्या आपने रनटाइम के दौरान वीएस में आउटपुट विंडो की जांच की है? क्या कोई बाध्यकारी त्रुटियां हैं? पूरे दृश्य के लिए आप 'DataContext' कहां सेट करते हैं? – nemesv

+0

ओह, यह टैग में डेटाकॉन्टेक्स्ट = "{बाध्यकारी सापेक्ष स्रोत = {सापेक्ष स्रोत स्वयं}} है। –

उत्तर

13

DataContext="{Binding DocumentList}" के बजाय ItemsSource="{Binding DocumentList}" आज़माएं।

+0

यह टैग से डेटाकॉन्टेक्स्ट के साथ संयोजन में है जिसे @nemesv ने हल किया है। धन्यवाद। –

+0

अपना उत्तर दोबारा वोट दें और इसे स्वीकार करें, @NathanTornquist। हम यहां हमारे पावलोवियन प्रतिक्रिया से प्यार करते हैं। – Yatrix

+0

यह मुझे अभी तक स्वीकार नहीं करेगा। उसने बहुत जल्दी जवाब दिया। चिंता मत करो हालांकि, मैंने इसका ख्याल रखा। –

संबंधित मुद्दे