0
事件我建立基于代码here过滤器是不是在icollectionview
我已经转换代码VB.Net在WPF中filteredComboBox,因为这是该项目使用。正在使用的代码有一个调用来在属性中添加一个处理程序,但它不起作用。我很久没有做过这种风格的代码,而且有点迷路。任何想法可能在这里尝试解决这个问题?
这是C#
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
{
if (newValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(newValue);
view.Filter += this.FilterPredicate;
}
if (oldValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(oldValue);
view.Filter -= this.FilterPredicate;
}
base.OnItemsSourceChanged(oldValue, newValue);
}
原始分段这是转换的VB
<summary>
Keep the filter if the ItemsSource is explicitly changed.
</summary>
<param name="oldValue">The previous value of the filter.</param>
<param name="newValue">The current value of the filter.</param>
Protected Overrides Sub OnItemsSourceChanged(oldValue As IEnumerable, newValue As IEnumerable)
If newValue IsNot Nothing Then
'Dim view As ICollectionView = CollectionViewSource.GetDefaultView(newValue)
' AddHandler view.Filter, AddressOf Me.FilterPredicate
AddHandler CollectionViewSource.GetDefaultView(newValue).Filter, AddressOf Me.FilterPredicate
End If
If oldValue IsNot Nothing Then
Dim view As ICollectionView = CollectionViewSource.GetDefaultView(oldValue)
RemoveHandler view.Filter, AddressOf Me.FilterPredicate
End If
MyBase.OnItemsSourceChanged(oldValue, newValue)
End Sub
错误是“过滤器不是 'System.ComponentModel.ICollectionView' 的事件。
这不是一个事件,这是一个性质。问题的哪一部分与c#有关? –
我知道这是一个属性,我正在重新使用示例代码,它的目标是工作,并且最初是用c#编写的(请参阅它的完整代码的链接) –
转换错误的代码不会产生良好的代码。如果你知道这是一个属性,然后按照它的意图使用它。 – OneFineDay