locked
"The Name 'InitializeComponent' Does Not Exist In The Current Context - C# RRS feed

  • Question

  • My WPF displays correctly, and this is a Build of a solution given by MSDN.

    The error displays at NearPlaneDistance="1"

    <Viewport3D.Camera>
                    <PerspectiveCamera 
    FarPlaneDistance="20" 
    LookDirection="0,0,1" 
    UpDirection="0,1,0" 
    NearPlaneDistance="1" 
    Position="0,0,-3" 
    FieldOfView="45" />
                </Viewport3D.Camera>

    Friday, May 22, 2015 12:49 AM

Answers

  • namespace WpfApplication2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }
    }

    THIS is the code the error was referring to.  In the .cs page, not the .xaml page.

    The error meant that "InitializeComponent" did not need to go there, so I removed it.

    That was it!!

    Friday, May 22, 2015 9:24 PM

All replies

  • Hi TheRedGuy1990,

    Based on your code snippet, I could not find any issue. But based on your exception information, I think it’s about namespace, I suggest that you could check your namespace in xaml code. You could refer to this thread about “The name 'InitializeComponent' does not exist in the current context in WPF application”: http://stackoverflow.com/questions/24693000/the-name-initializecomponent-does-not-exist-in-the-current-context-in-wpf-appl

    After that, if your issue was still existed, please Share your reproducible code sample and post link here.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 22, 2015 6:27 AM
  • I have very little experience with this sort of thing but I suggest you take a look at this article:

    http://www.codeproject.com/Articles/23332/WPF-D-Primer

    Note this markup from there:

    <Viewport3D.Camera>
        <PerspectiveCamera x:Name="camera" FarPlaneDistance="50"
            NearPlaneDistance="0" LookDirection="0,0,-10" UpDirection="0,1,0"
                Position="0,0,5" FieldOfView="45" />
    </Viewport3D.Camera> 

    That article dates from 2008 and it's entirely possible things have moved on.

    It could be that or maybe it's some other aspect of the stuff you're working with.

    I would start with a working sample.

    Note.

    Msdn has been getting better but it used to be quite prone to errors in sample code.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Friday, May 22, 2015 6:33 AM
  • The error "The Name 'InitializeComponent' Does Not Exist In The Current Context" does most probably not have anything to do with the Viewport3D.Camera markup that you posted.

    As Xavier Eoro suggests you need to make sure that the type of the root element in the markup of your view matches the one in the code-behind of the partial class:

    <Window x:Class="WpfApplication5.MainWindow" ...

    namespace WpfApplication5 {
    public partial class MainWindow : Window
      {
    ...
    }

    Please refer to the following link for more information: http://stackoverflow.com/questions/6925584/the-name-initializecomponent-does-not-exist-in-the-current-context

    You can try to create a new window (or user control or whatever you view type is) and simply copying your methods and markup over from the old files to the new ones (the .xaml and the .xaml.cs files).

    If this doesn't work and if the issue still remains then please upload a reproducable sample of your issue to OneDrive and post the link to it here for further help.


    Please also remember to mark helpful posts as answer to close the thread and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Friday, May 22, 2015 8:49 AM
  • namespace WpfApplication2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }
    }

    THIS is the code the error was referring to.  In the .cs page, not the .xaml page.

    The error meant that "InitializeComponent" did not need to go there, so I removed it.

    That was it!!

    Friday, May 22, 2015 9:24 PM