Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Cannot create an istance of ChildView error

$
0
0

In my parent view, I embed child views. One of child view is called "SelectionView". So my xaml code:

<StackPanel Orientation="Vertical" HorizontalAlignment="Left" ><localViews:SelectionView DataContext="{Binding VmSelect, Mode=TwoWay}" Visibility="{Binding IsSelectionViewVisible,Converter={StaticResource BooleanVisibilityConverter}}"></localViews:SelectionView></StackPanel>

In the parent view model(MVVM). I have the property

  public SelectViewModel VmSelect
        {
            get
            {
                if (this.vmSelect == null)
                    this.vmSelect = new SelectViewModel();
                return this.vmSelect;
            }
            set
            {
                if (this.vmSelect != value)
                {
                    this.vmSelect = value;
                    this.OnPropertyChanged("VmSelect");
                }
            }
        }

Also in the child view model constructor. I have

public SelectViewModel()
        {
            InitializeViewModel();
        }
private void InitializeViewModel()
        {
            LoadMenuItems();
            currentTabIndex = 0;
            this.Date = Helper.MinimumDate;
  // blah
     }

In the code behind of child view. I have the constructor

 public SelectionView()
        {
            try
            {
                InitializeComponent();
                InitializeViewExtras();
            }

 private void InitializeViewExtras()
        {
            InitializeLoadEvent();
            myApp = Application.Current as App;
        }

 private void InitializeLoadEvent()
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                this.Loaded -= SelectionView_Loaded;
                this.Loaded += SelectionView_Loaded;
            }
        }

My question is that I get the exception: Cannot create an instance of "SelectView". The details are

SelectionView..ctor()
So what is wrong?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>