How to set a window controllers Appearance and title in Visual Studio? - c#

I have recently downloaded Visual Studio for Mac and have created a new Cocoa Project as shown below.
I have found the storyboard file that I am able to use inside this project to create the UI and have started doing so. On the internet I found that you are able to set the appearance and the titleVisibilty of a window controller inside Xcode so that it looks like this:
The problem I'm having is I have no idea where to put the two lines of code that actually change these features of the window controller as I have never used this type of project before. I am hoping someone is able to tell me which file I should implement these changes in and how to write the code that is needed?
Thank You.

Related

Item Templates Sometimes Missing in Visual Studio 2017

Using Visual Studio 2017, sometimes new item templates are missing, and it seems to be tied to the particular project to which I'm trying to add an item.
Although both show up as "C#" projects...
...in "Logging", for WPF items, I have only UserControl (WPF) as an option:
However, in "SanityCheck", I have a much-more-full list of WPF options:
The only difference I can easily see so far is that the one ("Logging") is a Class Library project while the other ("SanityCheck") is a Windows Application project. However, changing Logging to Windows Application doesn't make more options available, and I ought to be able to create a Window in a Class Library, right?
I also noticed that Logging didn't contain all the same references as SanityCheck, so I added all the ones that seemed possibly-related, and that also didn't make any difference in the set of templates available.
So how do I get my Logging project to let me add a WPF Window?
Thanks to a comment from ASh and the list referred to from this question, I determined that the cause was a missing <ProjectTypeGuids> block in the Logging.csproj file. I copied the one from the SanityCheck.csproj file and now all the C# WPF templates are available. So far I haven't encountered any negative side-effects to this solution. Time will tell.

Did not find new element in the hierarchy for item

I am trying to create a simple page for a Xamarin app but am completely unable to proceed with the most basic of steps. I check out the branch from the project repo, and attempt to add a new file. When I do so (Right clicking on folder, Add-> New Item->Content Page) I get this error:
It does actually create the .xaml file but not the .xaml.cs file to go with it. I first tried to manually create the cs file and associate it but ran into increasingly mysterious errors. Today I created them outside of VS before booting it up and both files are now present but with the dotted icon instead of a regular one and the cs file is not nested beneath the xaml file.
If I try to open my projitems file inside VS to make the association I am given the error "Specified method is not supported". If I choose to 'Open With', no screen ever pops up allowing me to choose. After this I closed down VS and edited the projitems file in notepad again and linked the xaml and cs file. This looked as though it worked but when I add it to the main TabbedPage with a simple Children.Add(new MyReviews()); it is not recognized -> The type or namespace name 'MyReviews' could not be found.
These error happen if I make my own branch based on the master or try to add a new file to the master directly. No one else in the project is having these errors.
The only thing I really did differently from the rest is try to get the emulator working for android which apparently has a lot of compatibility issues and requires older versions of the xamarin plugins. I was not able to do this and ended up uninstalling and reinstalling everything twice since I didn't touch the installer software the first time and everything stuck.
Is anyone able to help me debug these issues or know why I am encountering so many at every turn?
I've been in the exact same situation. As it turned out, the rest of my team had added Universal Windows Platform (UWP) support to their VS2017 install, and I hadn't. Running the Visual Studio Installer and adding UWP fixed this issue completely.
Of course, you might not need or want to include UWP support in any of your Xamarin apps (I didn't). It seems most likely that it's just one or two support assemblies that are mssing or wrong without the UWP support, but I haven't found the time or energy to figure out any more details.

Page does not exist build error in xamarin

I have done a fresh install of VS2015 Community with Xamarin. I created a xaml page in the portable project. Then I see the most common error people have been cribbing about, InitializeComponent does not exist in the current context. A lot of solutions have been suggest by people.
Finally what worked was changing the build property of my Hellopage.cs to Embedded resource. But once that is done in the App.cs where you set the Mainpage, I see red squiggly lines which say that my Hellopage does not exist?
This is how I'm trying to set the mainpage.
MainPage = new Hellopage();
Anything that I'm missing?
Worked Solution Link
I've had this problem before and the reason was that the XAML files weren't processed correctly. What you should try is this:
In the properties pane of Hellopage.xaml, see Custom Tools
Change the value to MSBuild:Compile or something else
Click around to make sure Visual Studio processes the change
Change the value back to MSBuild: UpdateDesignTimeXaml
Another thing you can try is open the xaml and xaml.cs files and save them.

Visual Studio 2015 - Xamarin - Android - Getting "resource.id does not contain a definition for xxx" when I try to do anything in the .cs file

Adding Additional Activity .cs and Layout axml Using Visual Studio 2015.
I'm very new to Xamarin and Android development, but have been a developer for a few years using VB and now C#. I have a simple app on Android 4.2 that is getting more complicated as I go along. The simple matter us that I want to add an additional GpsAction.cs and corresponding Gps.axml layout to the project. It seems impossible to find the right combination syntax to achive this. I have a mainActivity with main.axml. In VS 2015 it's very simple to add new but I keep getting "resource.id does not contain a definition for" I would really appreciate your help with this
namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GpsLayout);
string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
// Create your application here
}
}
For people who are still facing this issue, the default Build Action of the layout file would be set to TransformFile. Select the layout, go to the Layout Properties, and in the properties pane, Select AndroidResource as your Build Action. Clean build your project and it should work.
I changed the text field "id" from "#+id/imageView1" to "1", saved, rebuilt and changed it back to "#+id/imageView1", it fixed it. I would like to add, this whole problem came from
Adding a new activity and layout.
Using preexisting code from another app that I had.
Copying and pasting code from the original app to the new Activity
and Layout.
All fairly common stuff, the real problem seemed always to be adding any new Activities and Layouts to a main Activity. It can get very convoluted and with no (known to me) logical way to run down a problem with Xamarin. Don't get me wrong compared to 10 years ago (the last mobile app I tried to write) Xamarin is heaven. Good coding folks, now if I can only figure out why Keyword "this" is error-ring on the added Activity.cs
Just add namespace like that Android.Resource.Id - it's resolve for me
What did work for me (Visual Studio 2017, opening an old Xamarin project):
Delete obj and bin folders, build.
If errors, restart Visual Studio (I know the pain).
Build again
Now the Resource will be visible (of course, if you defined it correctly).
The best solution I have found is to build solution.
Choose Build solution from Build menu (or Ctrl+Shift+B).
This action will resolve the issue.
You Should add set value forandroid:id="#+id/button1" in axml of app, then rebuild the project and try again.
like thisButton button = (Button)FindViewById(Resource.Id.button1); .
Check if you are missing these namespaces in your layout file -
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
(VS 2019) I did the previous solutions and nothing, I had the same problem and the solution for me was to remove '&' from the text of TextView, I was trying to Set the text to "text&text" even &&(I though it was like mnemonics as in WindowsForms) didn't work so I had to remove it and it fixed.
Cleared Main.axml page and Reset and it is working.
My problem was I was trying to debug Xamarin Android project (native) using Xamarin Live Player, connecting using USB cable and selecting my device for debugging solved the problem
Make sure your axml is well formed and rebuild the solution it should work, if you continue facing the same issue then remove axml and add it again then build the solution.
In Visual Studio 2019 when you add a new Android Layout to the Project it is added as .xml file. I already had some created earlier layouts in Resources/layout folder with extension .axml (not .xml) and for me changing the extension .xml -> .axml worked.
I understand that this issue is very old, but I've run into it as well in Visual Studio 2019, and have found a solution.
The issue occurs, for me, when adding an element to the layout and then attempting to add code. The issue appears to be related to the way the project is built.
Add the element to your layout, then build your project before adding any additional code. Apparently Resource.Id does not update with additional members until it's built, and attempting to refer to the new member in the code before Resource.Id recognizes it prevents the project from being built.
Like Maniacz said, in VS 2019 I just had to change the XML to axml extensión to the layout in layout folder under resources
For anyone else looking for an answer despite running clean/build/rebuild which didn't work for me:
I had freshly installed a number of tools for xamarin development in VS. Though a build/rebuild may have actually worked, in my case I believe what also fixed it was closing and re-opening VS. I'm pretty sure I had a few issues, primarily stemming from newly installed tools (android SDKs in my case) requiring VS to be restarted. If you're working on a project already having installed the tools you need, try as others have said - build/rebuild.
I had to modify Build Action for my layout file and re set the original Build Action as it was previously set. This made my visual studio to regenerate the resource ids in Resource.designer.cs file.
Step #1:
Go to properties of the layout file that is missing its ids and click the Build Action DropDown.
Step #2:
Select something from the dropdown other than AndroidResource.
Step #3:
Reselect AndroidResource from that Build Action.
Now, you will have your Resource.designer.cs file regenerated and it will have the reference ids to your controls in the layout file.
Check the Resource.Designer class file. There will be a class like public partial class Id. There the integer IDs of the controls are written. Use them instead of Resource.Id

WPF Project with Custom XAML Controls

I am new to WPF coding. I have a project that has custom controls coded as xaml's with C# code-behinds. I try to import these files into another project and when I try to use these xaml controls in my main view file, Visual Studio cannot find the namespace that the imported xaml's and C# code-behinds are attached to.
I tried changing the namespace to be the same as my current project. I tried restarting Visual Studio 2013. Neither of these worked.
I tried adding the project with the custom controls to my solution. The imported project can read the custom xaml's, but my main project still can't reference them. I tried dragging the files over to the main project, and they still won't work.
I tried rebuilding the controls xaml's and C# code-behinds in my new project it still says:
The type 'local:ClickSelectTextBox' was not found. Please verify that that you are not missing an assembly reference and that all reference assemblies have been built.
This item is under the appropriate namespace and in the current project.
In visual studio go to TOOLS -> choose Toolbox Items. this will allow you either choose from an array of different components or browse around to find a dll that you would like to use.
EDIT:
Oh so you are trying to take customized xaml files that you already have written and modify them in a separate project? I would suggest one of two things.
1: right click your project name -> add existing, and add the xaml and xaml.cs file to your project at the same time.
if for some reason that does not work you can also try
2: creating a new xaml control (with the same name of the control you want to drop in) in your project and copy pasting the xaml code into that control, this should autogenerate the codebehind designer shell you are going to need. you can then go into the xaml.cs file and drop whatever business logic you are looking for. It is not the cleanest solution but sometimes the WPF editor gets a little funky when importing xaml files
I know it's an old post but still somebody may find it useful:) So! ... Make sure
1)You don't have public class outside of root namespace, check this
link
2)You are not mixing targets of your assemblies (unless you can't 100% avoid that)
For example, if you are referencing something like SQLite.Core NuGet (that has both x86 and x64 versions of SQLite.Interop.dll built in) in a project that is AnyCPU, sometimes it's easier to set application's target to x86 or x64 to solve the x86/x64 paths issues - but then you may get all these "type not found/control not built/assembly not found" and all that sorts of nonsense from Designer even despite your app builds and runs ok.
Hope that helps
Try downloading ReSharper's trial version, install it and then open up your code again. One of the awesome features Resharper has with XAML code is that it will automatically map objects to their appropriate namespace. I think this will make it easier for you and will show you a ton of ways to do things better. When I was first learning WPF it was honestly a godsend to use Resharper.

Categories

Resources