Search code examples
xamarinxamarin.iosjetbrains-iderider

How to set property for Xamarin.ios view in Rider? (How to update autogenerated View.designer.cs?)


If I am using Visual Studio for Mac it has this field in the designer.

It creates a property in the View.cs file that allows me to bind to it.

enter image description here

I found a similar section in xcode (that is what rider opens up) and it only has these options. No field for Name.

enter image description here

This name field is not what shows up on the button label. I know how to set that.

I would much rather use Rider than Visual Studio for mac. If I have to constantly jump back and forth this would obviously be a problem.

EDIT: From what I can tell, it seems to edit the View.designer.cs.

It has this comment though. How would I be able to edit this from Rider?

// WARNING
//
// This file has been generated automatically by Visual Studio from the 
outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//

This was what it looks like on default with a new MvvmCross project

using Foundation;
using System;
using System.CodeDom.Compiler;

namespace HelloCrossPlatform.iOS.Views
{
[Register ("FirstView")]
partial class FirstView
{
    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UILabel Label { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UITextField TextField { get; set; }

    void ReleaseDesignerOutlets ()
    {
        if (Label != null) {
            Label.Dispose ();
            Label = null;
        }

        if (TextField != null) {
            TextField.Dispose ();
            TextField = null;
        }
    }
}
}

Here is what it looks like when I add the name property to the button in Visual Studio for Mac with the Designer

using Foundation;
using System;
using System.CodeDom.Compiler;

namespace HelloCrossPlatform.iOS.Views
{
[Register ("FirstView")]
partial class FirstView
{
    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UILabel Label { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UIButton SayHelloButton { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UITextField TextField { get; set; }

    [Action ("UIButtonDZD114An_TouchUpInside:")]
    [GeneratedCode ("iOS Designer", "1.0")]
    partial void UIButtonDZD114An_TouchUpInside (UIKit.UIButton 
sender);

    void ReleaseDesignerOutlets ()
    {
        if (Label != null) {
            Label.Dispose ();
            Label = null;
        }

        if (SayHelloButton != null) {
            SayHelloButton.Dispose ();
            SayHelloButton = null;
        }

        if (TextField != null) {
            TextField.Dispose ();
            TextField = null;
        }
    }
}
}

Is rider even a good tool to use with Xamarin? I'm getting disappointed they even market it as an option. Really questioning my subscription to JetBrains.. Vscode seems to work just as well as Webstorm which is the only other product I work with from them.


Solution

  • Rider does NOT have a special designer for .xib and .storyboard UI files. We (the Rider team) think we will not be able to implement as good (and actual) UI designer as the native xcode is. So the main scenario to work with Xamarin macios UI in Rider - use xcode interface builder.

    You can check the apple documentation about outlets generating: https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ConnectingObjectstoCode.html

    This is a brief description how to do it in xcode 11 with default settings.

    1. Split UI editor into designer and source parts Step 1

    2. Ctrl+Click the control you want to bind and drag it into the code. Important note: use .h files to create new actions and outlets, Rider analyzes .h files to build a public API model. Step 2

    3. Now you can enter the name of the control it the binding will be created. You will see corresponding outlets in objc code.

    Maybe it is not that straightforward so I will try to explain how it works internally. Xamarin macios project is an (almost) regular .NET C# project. So to allow you edit UI in the xcode, Rider (and VS actually) do some magic. It takes the .NET project and:

    1. Creates the corresponding xcodeproj (pbxproj and friends) project in obj\xcode folder with specific settings and configurations.
    2. Copies all content like views, plist files, images and so on.
    3. Looks for all ViewController types. For each of them Rider generates objc class with actions and outlets.
    4. Opens xcode and the generated project into.

    When you have made some changes in that generated project and go back to Rider, it tries to apply all changes:

    1. Copies all changed content files back into .NET project
    2. Updates settings
    3. Parses objc files and regenerate *.designer.cs files for view controllers. For all these files you will see this generated header (can be changed in the future):
    // WARNING
    //
    // This file has been generated automatically by Rider IDE
    //   to store outlets and actions made in Xcode.
    // If it is removed, they will be lost.
    // Manual changes to this file may not be handled correctly.
    //
    

    To control xcode synchronization process and see whats going on and see what errors occur you can use a special Rider toolwindow: xcode console. It is shown each time you open a project in xcode:

    xcode console in Rider

    Instead of conclusion: Rider's team tries to provide good experience for Xamarin Developers, even better then VS for Mac. So are working on support some Xamarin parts (Xamarin Forms Hot Reload in the 2020.1) so feel free to share your troubles in our public issue tracker:

    https://youtrack.jetbrains.com/issues/RIDER?q=Technology:%20Xamarin%20