我有两个ObservableCollections,我需要在一个ListView控件中一起显示它们.为此,我创建了MergedCollection,它将这两个集合显示为一个ObservableCollection.这样我就可以将ListView.ItemsSource设置为我的合并集合,并列出两个集合.添加工作正常,但当我尝试删除项目时,显示未处理的异常:
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Additional information: Added item does not appear at given index '2'.
Run Code Online (Sandbox Code Playgroud)
MergedCollection的代码如下:
public class MergedCollection : IEnumerable, INotifyCollectionChanged
{
ObservableCollection<NetworkNode> nodes;
ObservableCollection<NodeConnection> connections;
public MergedCollection(ObservableCollection<NetworkNode> nodes, ObservableCollection<NodeConnection> connections)
{
this.nodes = nodes;
this.connections = connections;
this.nodes.CollectionChanged += new NotifyCollectionChangedEventHandler(NetworkNodes_CollectionChanged);
this.connections.CollectionChanged += new NotifyCollectionChangedEventHandler(Connections_CollectionChanged);
}
void NetworkNodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
CollectionChanged(this, e);
}
void Connections_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
CollectionChanged(this, e);
}
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
for …Run Code Online (Sandbox Code Playgroud) 我已经为我的应用程序设置了一个部署项目.问题是我想在安装期间显示应用程序版本(例如MyApplication 1.2.3.1),以便用户在安装之前可以看到该版本.
我能想到的唯一方法是在Welcome对话框中修改WelcomeText.是否有更简单或更优雅的方式来实现这一目标?