काम नहीं करता है यहाँ XAML है:ElementName साथ बाइंडिंग
<DataGrid Grid.Column="0" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Path=Columns}"
x:Name="ColumnsGrid" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding Path=Header}"
Header="{Binding ElementName=ColumnsGrid, Path=DataContext.Count, StringFormat=Columns ({0}), diag:PresentationTraceSources.TraceLevel=High}"/>
</DataGrid.Columns>
</DataGrid>
बाध्यकारी रिटर्न त्रुटि: System.Windows.Data त्रुटि: 2: FrameworkElement या FrameworkContentElement लक्ष्य तत्व के लिए शासी नहीं मिल सकी।
मुझे क्या याद आती है?
What is happening here? The Columns collection is just a property in the Datagrid; this collection is not in the logical (or visual) tree, therefore the DataContext is not being inherited, which leads to there being nothing to bind to.
अद्यतन 2: डेटा ग्रिड के चेतावनियां के बारे में अच्छा लेख:
यहाँ जवाब है http://blogs.msdn.com/b/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx
मुझे नहीं लगता कि 'ElementName' * एक ही तत्व के भीतर * काम करता है । – ChrisF
यहां जवाब है: http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx > क्या यहाँ हो रहा है? कॉलम संग्रह डाटाग्रिड में सिर्फ > एक संपत्ति है; यह संग्रह तार्किक (या दृश्य) > पेड़ में नहीं है, इसलिए डेटाकॉन्टेक्स्ट विरासत में नहीं मिला है, जिससे > बाइंड करने के लिए कुछ भी नहीं है। –