複製的代碼我有一個覆蓋問題。我知道你不能覆蓋繼承成員,除非它們被標記虛擬,抽象或重寫,但...無法覆蓋繼承成員SelectTemplate ...與我從MSDN
我this code從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
我一直在尋找WH花了幾個小時Ÿ,但無法弄清楚。有任何想法嗎?
所以我不得不做出兩個改變:從「公共覆蓋...... SelectTemplate」到「保護覆蓋SelectTemplateCore」那工作。 –