我有一个覆盖问题。我知道你不能覆盖继承的成员,除非它们被标记为虚拟、抽象或覆盖,但是......
我有 这个来自 msdn 的代码:
using System.Windows;
using System.Windows.Controls;
namespace SDKSample
{
public class TaskListDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate
SelectTemplate(object item, DependencyObject container)
{
FrameworkElement element = container as FrameworkElement;
if (element != null && item != null && item is Task)
{
Task taskitem = item as Task;
if (taskitem.Priority == 1)
return
element.FindResource("importantTaskTemplate") as DataTemplate;
else
return
element.FindResource("myTaskTemplate") as DataTemplate;
}
return null;
}
}
}
我添加了这段代码:
public class PostTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
ListViewItem lvi = item as ListViewItem;
AppNetClient.PostClass key = lvi.DataContext as AppNetClient.PostClass;
if (key.postTemplate == "Post")
{
return lvi.FindName("PostDataTemplate") as DataTemplate;
}
else
{
return lvi.FindName("SelectedPostDataTemplate") as DataTemplate;
}
}
}
我得到这个错误:
Error 3 'oneSocialLife.MainPage.PostTemplateSelector.SelectTemplate(object, Windows.UI.Xaml.DependencyObject)': cannot override inherited member 'Windows.UI.Xaml.Controls.DataTemplateSelector.SelectTemplate(object, Windows.UI.Xaml.DependencyObject)' because it is not marked virtual, abstract, or override C:\Users\kcone\documents\visual studio 2012\Projects\HttpClientApp\HttpClientApp\MainPage.xaml.cs 339 42 oneSocialLife
我花了几个小时寻找原因,但无法弄清楚。有任何想法吗?