Search code examples
c#xbap

The 'InitializeComponent' and '_FrameViews' does not exist in the current context


I'm in the process of learning WPF, so in my case I have an xbap application and the code below is the code behind MainView.xaml.cs. Also, it was initially of a Page Type and I just changed it to UserControl recently because I need to deploy this app using ClickOnce.

List of errors:

  1. The name 'InitializeComponent' does not exist in the current context.
  2. The name 'FrameViews' does not exist in the current context.
public partial class MainView : UserControl
   {
       public MainView()
       {
           InitializeComponent();

           this.DataContext = MainViewModel.UniqueInstance;
           MainViewModel.UniqueInstance.FrameNavigationService = _FrameViews.NavigationService;

           _FrameViews.Unloaded +=new RoutedEventHandler(_FrameViews_Unloaded);
       }

       private void _FrameViews_Unloaded(object sender, RoutedEventArgs e)
       {
           _FrameViews.Content = null;
       }

   }
}

Solution

  • The InitializeComponent() is only available in MainWindow not in MainView you need to write like that:

    public partial class MainWindow : Window
    

    and the _FrameView doesent exist you need to declare it