从我的角度看,一切看起来都很好,但dataGrid只显示已添加到网格中的第一个项目。
XAML部分:
<DataGrid HorizontalAlignment="Stretch" Name="dataGridIE"
VerticalAlignment="Stretch" HeadersVisibility="All" CanUserReorderColumns="False" CanUserResizeColumns="False"
AutoGenerateColumns="True" ColumnWidth="100" CanUserAddRows="True" CanUserDeleteRows="True"
Height="97" Margin="23,38,16,38" Grid.ColumnSpan="2" Width="682">
<!--<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" />
<DataGridTextColumn Header="Value" Binding="{Binding Value.xPath}" />
</DataGrid.Columns>-->
</DataGrid>
列表的声明部分(代码隐藏):
private List<IEGridViewEntry> _fillEntryDictionary;
需要绑定的结构:
public struct IEGridViewEntry //: INotifyPropertyChanged
{
private ...
public string wordPlaceHolder
{
get { return _wordPlaceHolder; }
set { _wordPlaceHolder = value; }
}
...
};
我填写它的方式:
_fillEntryDictionary.Add(new IEGridViewEntry(refHtmlElement));
dataGridIE.ItemsSource = _fillEntryDictionary;
调试时,一切看起来都很好并且已经填满..
_fillEntryDictionary = Count = 2
[0] = {name1.name.IEGridViewEntry}
复制表达式(调试):
(new System.Collections.Generic.Mscorlib_CollectionDebugView<name1.name.IEGridViewEntry>(_fillEntryDictionary)).Items[0]
提前致谢。
答案 0 :(得分:2)
为datagrid设置ItemsSource =“{Binding}”,并使用设置.DataContext = ObservableColelction填充它,而不是设置List