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.
Related
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.
sorry if this questions been asked already, I suspect it's quite common..
I'm using Xamarin for Visual Studio 2015 (4.0.3.214), and a common thing is that every now and again after saving or loading the project all the variables associated with the MainPage.xaml file are red, i.e. showing up as errors in the solution error list.
By retouching - saving the file after an edit (like adding a space then doing a backspace so nothing changes), the errors go away.
Which suggests a problem with the way Xamarin handles the build process and keeps track of auto-generated files. Is there a solution or a fix to this, or even a proper explanation ?
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).
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.
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.