在WPF-Datagrid中显示List时遇到问题。当我这样做时
... DocumentList dt = new DocumentList(fileWordList, fileUriType, fileUri, cosineSimilarityRatio, diceSimilarityRatio, extendedJaccardSimilarityRatio); documentList.Add(dt); ... dataGrid1.Items.Add(dt); ...
它会在dataGrid1中创建一个空行,并且不会显示任何文本。
我的xaml实现是:
<GroupBox Canvas.Left="-0.003" Canvas.Top="0" Header="Display Results" Height="427.5" Name="groupBox2" Width="645.56">
<toolkit:DataGrid Canvas.Left="137.5" Canvas.Top="240" Height="392" Name="dgrDocumentList" Width="627" ItemsSource="{Binding DocumentList }">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Header="Type" Binding="{Binding type}" IsReadOnly="True">
</toolkit:DataGridTextColumn>
<toolkit:DataGridHyperlinkColumn Header="Uri" Binding="{Binding path}" IsReadOnly="True">
</toolkit:DataGridHyperlinkColumn>
<toolkit:DataGridTextColumn Header="Cosine" Binding="{Binding cos}" IsReadOnly="True">
</toolkit:DataGridTextColumn>
<toolkit:DataGridTextColumn Header="Dice" Binding="{Binding dice}" IsReadOnly="True">
</toolkit:DataGridTextColumn>
<toolkit:DataGridTextColumn Header="Jaccard" Binding="{Binding jaccard}" IsReadOnly="True">
</toolkit:DataGridTextColumn>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</GroupBox>
和我的DocumentList类
class DocumentList
{
public List<WordList> wordList;
public string type;
public string path;
public double cos;
public double dice;
public double jaccard;
//public static string title;
public DocumentList(List<WordList> wordListt, string typee, string pathh, double sm11, double sm22, double sm33)
{
type = typee;
wordList = wordListt;
path = pathh;
cos = sm11;
dice = sm22;
jaccard = sm33;
}
我想这样做:当我向documentList实例中添加一个新元素时,希望在数据网格上看到结果。 提前谢谢。
答案 0 :(得分:3)
您只能绑定到属性,因此请将DocumentList公共字段更改为公共属性。