【发布时间】:2020-04-07 21:51:57
【问题描述】:
WPF 的代码非常简单:
<telerik:RadGridView Name="AnalisiKey"
AutoGenerateColumns="True"
Margin="10,273,694,59"
d:DataContext="{d:DesignInstance Type=viewModels:FrequentKeywordFinderViewModel, IsDesignTimeCreatable=True}"
ItemsSource="{Binding ItemCollectionViewSourceSingole}"
ClipboardCopyMode="All" SelectionMode="Extended" SelectionUnit="Mixed">
<!--<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="Keyword" Header="Keyword" Language="it-it" DataMemberBinding="{Binding (viewModels:KeyFreq.Keyword)}" />
<telerik:GridViewDataColumn x:Name="FreqNelDocum" Header="FreqNelDocum" Language="it-it" UniqueName="FreqNelDocum"/>
</telerik:RadGridView.Columns>-->
</telerik:RadGridView>
以及 ViewModel
class FrequentKeywordFinderViewModel : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider) => this;
public List<KeyFreq> ItemCollectionViewSourceSingole { get; set; } = new List<KeyFreq>();
}
以及填充 ItemSource 的代码:
private void MostroRisultatiSuGriglia(List<KeyFreq> singole,
List<KeyFreq> doppie, bool excludeUnfrequentKeys)
{
var dataContext = ((FrequentKeywordFinderViewModel)this.DataContext);
var itemCollectionViewSourceSingole = dataContext.ItemCollectionViewSourceSingole;
singole = CalcolaTfIdf(StopWordsUtil.FrequenzaKeywords, singole);
dataContext.ItemCollectionViewSourceSingole.AddRange(singole.Where(s => s.FreqNelDocum > 1).ToList());
itemCollectionViewSourceDoppie.Source = doppie.Where(s => s.FreqNelDocum > 1).ToList();
}
使用 Snoop,我可以深入研究 datagrid.ItemSource 并查看项目。但它们不会出现在数据网格中。有什么建议吗?
【问题讨论】:
-
不清楚 MarkupExtension 是从什么派生的,但是 (1) 您的 ViewModel 类应该从 INotifyPropertyChanged 派生,并且 (2) 您的 ItemCollectionViewSourceSingole 设置器应该调用 PropertyChanged 事件并且 (3) 您的 ItemCollectionViewSourceSingole 应该是 ObservableCollection 而不是而不是一个列表,因为你在一个不同于它的构造的动作中填充它。
-
@Zenilogix:非常感谢。您可以将其转换为答案吗?然后我会添加一些额外的代码或截图来完成它。