Sitrep:我有一个列表视图/网格视图,处于半无足的MVVM样式设置中。 我有一个存储数据的自定义对象。在OberservableCollection中。
在通知属性更改事件触发然后整个应用程序似乎冻结
之前,一切似乎都很好注意:此ObservableCollection有大约24000个项目
这是代码。
标准通知属性已更改
public class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(Object PropertyValue, Object PropertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(PropertyValue.ToString()));
}
}
视图模型:
public ObservableCollection<ObjectModel.EventEntry> EventViewerDisplayData { get; set; } //Property bound to view
public void DelegatedChangeLog(Object Parameters)
{
EventViewerDisplayData = new ObservableCollection<ObjectModel.EventEntry>(new EventViewerMode(Paramters.ToString()); //Evaluates and data gets stored
NotifyPropertyChanged("EventViewerDisplayData"); //Program Freezes
}
如果我将列表限制为1项,则可以正常工作 任何想法?
作为请求XML代码:
Mainwindow.xml
<ListView ItemsSource="{Binding EventViewerDisplayData}" DataContext="{Binding EventViewerContext}" Style="{StaticResource GroupedListView}">
</ListView>
StaticResource的:
<Style TargetType="{x:Type ListView}" x:Key="GroupedListView">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<ListView ItemsSource="{TemplateBinding ItemsSource}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ToolTip" Value="{Binding Description}"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Icon}" Width="30"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Source}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Event ID" DisplayMemberBinding="{Binding EventID}" />
<GridViewColumn Header="Severity" DisplayMemberBinding="{Binding SeverityName}" />
<GridViewColumn Header="Time" DisplayMemberBinding="{Binding Created}"/>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Header="{Binding Name}" Width="{Binding Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}">
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
DataGrouping按要求
private void GridSorting(String Description)
{
System.ComponentModel.ICollectionView NewView = System.Windows.Data.CollectionViewSource.GetDefaultView(EventViewerDisplayData);
NewView.GroupDescriptions.Add(new System.Windows.Data.PropertyGroupDescription(Description));
}