我有一个dialogContent TemplateSelector,用于打开一个对话框。我收到这个错误;
错误2' CentralPrintUnitSystem.Dialogs.DialogContentTemplateSelector.SelectTemplate(object,System.Windows.DependencyObject)&#39 ;:并非所有代码路径都返回值C:\ Users \ 2337704 \ documents \ visual studio 2012 \ Projects \ CentralPrintUnitSystem \ CentralPrintUnitSystem \ Dialogs \ DialogContentTemplateSelector.cs 22 53 CentralPrintUnitSystem
我的DialogContentTemplateSelector代码是;
namespace CentralPrintUnitSystem.Dialogs
{
public class DialogContentTemplateSelector : DataTemplateSelector
{
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
FrameworkElement element = container as FrameworkElement;
if (item != null && container != null)
{
if (item is CentralPrintUnitSystem.Dialogs.EditNewEntryDialogView)
{
return element.FindResource("EditNewEntryDataTemplate") as DataTemplate;
}
if (item is CentralPrintUnitSystem.Dialogs.EditNewDepartmentDialogView)
{
return element.FindResource("CreateNewDepartmentDataTemplate") as DataTemplate;
}
else
{
return null;
}
return null;
}
}
}
}
所有和任何帮助将不胜感激。
答案 0 :(得分:-2)
这应该可以解决这个错误 -
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
FrameworkElement element = container as FrameworkElement;
if (item != null && container != null)
{
if (item is CentralPrintUnitSystem.Dialogs.EditNewEntryDialogView)
{
return element.FindResource("EditNewEntryDataTemplate") as DataTemplate;
}
if (item is CentralPrintUnitSystem.Dialogs.EditNewDepartmentDialogView)
{
return element.FindResource("CreateNewDepartmentDataTemplate") as DataTemplate;
}
else
{
return null;
}
return null;
}
return null;
}