これは私が得たものです:PresentationFramework.dllで「System.NullReferenceException」タイプの最初のチャンス例外が発生しました
LessonPlannerViewModelクラスのコンストラクターにパラメーターを使用する場合。
週次表示と日次表示を切り替えるには、datatemplateselector クラスを使用します。
public class ApplicationNavigationTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is LessonPlannerViewModel)
{
var vm = item as LessonPlannerViewModel;
Window window = Application.Current.MainWindow;
if (vm.IsDailyView)
return window.FindResource("dailyViewTemplate") as DataTemplate;
else
return window.FindResource("weeklyViewTemplate") as DataTemplate;
}
return base.SelectTemplate(item, container);
}
}
public LessonPlannerViewModel(DateTime asOfDate)
{
_asOfDate = asOfDate;
if(_isDailyView)
LoadDailyData();
if(_isWeeklyView)
LoadWeeklyData();
...
それは許されませんか?パラメータがなければ例外はありません...
私は何を間違っていますか?
EDIT:今、私はパラメータを整数に変更し、より良いメッセージを得ました;P
XamlParseException=> 'タイプ 'TBM.ViewModel.LessonPlannerViewModel' に一致するコンストラクターが見つかりません。Arguments または FactoryMethod ディレクティブを使用して、この型を構築できます。行番号「13」と行位置「10」。
これで理解できるようになりました。
<UserControl.Resources>
<ViewModel:LessonPlannerViewModel x:Key="LessonPlannerViewModelID" />
</UserControl.Resources>
パラメータはありません。
では、今何をすべきか?