Visual studio 2017 c# design view fail to load after rename - c#

I'm working on a winform app.
The design view worked well until I renamed the Form1.cs to FormMain.cs.
The program itself is ok. It can be compiled with no error and it runs well(with right form). But visual studio keep warning me that there are mistakes in FormMain.cs. It seems that FormMain class in FormMain.Designer.cs is totally ignore as it alerts "InitializeComponent(); is not defined."
And the design view goes blank as if the form was just newly-created.
IntelliSense tells me the origin(not yet renamed) Designer.cs is not found.
Now if I try to create anything on the blank form, the code is directly written in FormMain.cs.
How can I solve this?
Thanks.

Using Visual Studio 2019, I was following the C# WPF tutorial from Microsoft docs. Along the way, there is a step wherein you rename MainWindow.xaml to Greetings.xaml. When I did this, the design view was gone. Restarting Visual Studio fixes the design view. Of course, save your files before restarting.

Removing the form and adding it again to the solution fixes this issue. Here's how you can do:
Right click on the FormMain in the solution explorer and "Exclude From Project". Now right-click on the solution and click Add -> Existing Item and select the FormMain.cs from the same solution folder.

Related

Disable Design View for C# Class in VS2019

My C# project displays classes in the Solution Explorer some with the Designer View and some with the normal code editor:
AND
I Would like to make them all open with the code editor!
I went in the .csproj file and I noticed that for the classes marked as designer, I get a
<SubType>Component</SubType> tag. If I remove it manually, VS automatically re-add it to the item.
How to solve it? I searched but did not found anything usefull..
EDIT 1: I forgot to mention that this is a Console Application

C# file (CodeBehind class) disappearing from project in Visual Studio - Xamarin

After adding a new Forms ContentPage with a CodeBehind class (Forms ContentPage XAML), everything works perfectly at first. As expected, it creates a .xaml file with a drop down leading to a .xaml.cs file. After adding code, I build my project, and the screens look and work as expected.
After quitting and returning to Visual Studio, however, the .xaml.cs file just disappears from the Solution. This completely breaks my project because Visual Studio can no longer read my event handlers within the .xaml.cs file. The strange thing is that when I press 'reveal in finder' I can see that the .xaml.cs file IS there.
Note, that this does not happen to all my files. Randomly some CodeBehind classes will just disappear from the Solution.
Has anyone else had this problem? What is going on?
I am using Visual Studio Mac 8.10 Community and this happens to me all the time, too. I make sure to push my projects to my GitHub rep permanently, so I have a backup. Try to use Rider instead of Visual Studio - it has less flaws according to my experience. If you have an Open Source GitHub Repository which your are committing regularly for 3 months, they will grant you a free license.

"Go To Definition" from a .xaml.cs file takes me to .g.i.cs files instead of to .xaml file in Visual Studio 2015

I am used to Visual Studio Go To Definition (or ReSharper's Ctrl + left click) in code behind on an element name defined in XAML to take me directly to XAML of that element. For some reason it's taking me to .g.i.cs file instead. Where as it's not a huge problem it is annoying as hell. This is also not specific to my project - I can create a new WPF project, add a single button to XAML and get the same result trying to go to the button's declaration in XAML from code behind file.
I tried to do the same thing in VS 2015 Professional on another computer and get the same problem.
But when I do this in Visual Studio Enterprise 2015 on my Surface, it works correctly and goes to XAML (all testing done with new WPF project) - I can't find any option anywhere that would control this.
Any ideas for this would be greatly appreciated.
Well, it seems as ReSharper actually changed the behavior - very naughty. I am happy to say that ReSharper 9.2 fixed this problem (I was using 9.1.3 initially).

In Visual Studio 2013 when I add an existing form then controls don't appear on designer

I'm working on a windows form application. I start a new project. I delete the Form1 stuff from the new project. I go and add from existing in the solution explorer and choose Form1.cs, Form1.Designer.cs, and Form1.resx from another project. When I look at the designer Form1 just looks blank, like a new one would with none of the controls appearing. The program still compiles fine with all it's controls intact. Did I miss a step somewhere? I've closed and reopened the project etc. This happens every single time repeatedly so I believe I'm missing something but searching here or the rest of the web hasn't provided me a solution. Maybe it's just assumed to be known by everyone already?
I am just learning c# and Visual Studio so hopefully I didn't miss something stupid. I was following direction for how to do this from a book. Some projects are re-used to teach a new idea so they have you start a new project and add in existing items from the original to then work on the new idea.
In VS 2013 I chose "Add existing Item" and just selected the .cs files, don't add *.Designer.cs and *.resx files. Then waited for few minutes and restarted VS2013. Designer.cs and resx files appeared as associated with Forms but they were excluded. I right clicked them and chose "Include In Project". Then it worked fine.
Make sure that you are loading the Form1 that you think you are loading.
By default, Visual Studio 2013 (on Windows 7) will create a folder in Documents (C:\Users*Your user name*\Documents) called "Projects". Whenever you create a new project from within Visual Studio by going to File->New Project, Visual Studio will (by default) create a new folder in the Projects folder with the project name.
I think when you "delete" Form1, you're not actually deleting it, just removing it from the project. When you go to add Form1, you're just selecting it from the same project folder, when you actually wanted to load it from a different project folder.
Try this: In your current project (the one where you deleted Form1 and then added it), in the Solution Explorer, right click on the project, and select "Open Folder in File Explorer".
This will open the project folder on disk. Now, delete Form1.cs from within Visual Studio, and switch back to the project folder. If Form1.cs is still in that project folder, then you just removed it from the project. The actual files still exist on disk. When adding existing items, Visual Studio will typically default to the selected project folder.
I have a very strong suspicion that the Form1 that you are really looking for resides in a different project folder. Without knowing the book or tutorial you are following, I can't give you any hints as to where the Form1 you want is located.

XAML UI updates not visible in code-behind

Having the same project opened in both, Visual Studio and Blend, I use the former to write code while I edit the XAML in the latter.
When I add an UI element to the .xaml file and save it in Blend, if I have that file opened in Visual Studio too, I see the message that some external changes have been done and asking if I want them to take effect in the opened file*. I accept it, and I can see the changes take effect in the .xaml file in Visual Studio.
The problem is, that although the new elements have been added to the .xaml file, I'm not able to access them throug Intellisense in the code-behind .cs file.
For example if I add following element to the MainPage.xaml using Blend:
<Button x:Name="MyButton" Content="Button"/>
I can see that same line added to the page in Visual Studio, but I cannot access it using the name MyButton in MainPage.xaml.cs file. Intellisense is not working for it. If I write, for example MyButton.Content = "Hello!"; it is red underlined, however I can build and run the project.
Rebuilding the project doesn't do the trick, and Intellisense doesn't work until I save the file "again" in Visual Studio.
I feel this behavior annoying sometimes, and I'd like to know if it is the normal behavior, or there is something wrong in my configuration.
*I usually don't have it opened in Visual Studio, just to avoid that meessage being shown for each modification in Blend
I have just check your problem actually it is not a issue. everything is fine so what you have to do is save your xaml page on which you have added the button after accepting the changes that was done in blend..(do control + s on your xaml page one more time it will work fine)..sorry for my bad english..
I encountered this issue when developing Xamarin Forms in Visual Studio 2015 and somehow the problem went away after I:
1) Unload project (right-click project and select from context menu)
2) Edit .csproj (from context menu)
3) Pretend to modify and save csproj. :)
4) Reload project (from context menu)
Closing the whole solution and re opening it fix my similar issue.

Categories