Custom control not showing up in toolbox

Hi, I've created a very simple custom control. But it doesn't show up in the toolbox in the iOS Designer, and I can't figure out why.
I've read about Custom Controls in the documentation, and I've followed the requirements, but it still doesn't show up. I've recompiled, rebuilt and reloaded the solution, and I've restarted VS, but nothing helps. So I'm actually beginning to doubt that the Visual Studio iOS Designer supports custom controls, but hopefully that's not the case.

Here is the code for the custom control. Can anyone see if I'm doing something wrong?

[Register("MyView"), DesignTimeVisible(true)]
public class MyView : UIView
{
    public MyView(IntPtr handle)
        : base(handle)
    {
    }

    public override void AwakeFromNib()
    {
        base.AwakeFromNib();

        this.Initialize();
    }

    private void Initialize()
    {
        // Gives the view a red, rounded border.
        this.Layer.CornerRadius = 5;
        this.Layer.MasksToBounds = true;
        this.Layer.BorderColor = new MonoTouch.CoreGraphics.CGColor(1.0f, 0.0f, 0.0f);
        this.Layer.BorderWidth = 2.0f;
    }
}

I'm using a storyboard in case that makes any difference.

If I drag a View from the Windows & Bars category in the Toolbox, and change it's class to MyView in the Properties window, the control is still rendered as a standard UIView in the iOS Designer. But then when I run the application in the simulator, the same control is rendered as my custom control, having a red rounded border.

How can I get my custom control to render in the iOS Designer, and how can I get it to show up in the Toolbox?

Posts

  • AlexCorradoAlexCorrado USXamarin Team Xamurai

    Just a random question, but does there happen to be any shared asset or PCL project in your solution?

  • RenGundersenRenGundersen DKMember

    Hi Alex, thank you for replying.

    No, there's only one project, and it's actually a very simple project that I created just to play around with the iOS Designer. So there's one storyboard with a navigation controller and 2 views, 1 View Controller class, and my custom control.

  • RenGundersenRenGundersen DKMember

    I just tested my solution on Xamarin Studio on OSX, and my custom control actually shows up in the Custom Components category here.

    So it seems it's a problem related to the Visual Studio iOS Designer.

  • michelTolmichelTol USMember ✭✭
    edited October 2014

    Hi @RenGundersen‌ ,
    did you find any solution for this issue? I am experiencing the same issue.

  • RenGundersenRenGundersen DKMember
    edited October 2014

    No, not yet. I need Xamarin to fix the pairing issues with Yosemite first, before I can work on this. And even then, there is some problems with iOS 8 in the VS iOS Designer they also need to fix. (The error 500 issue)

    So right now, I've just decided to go with Xamarin Studio on the Mac, instead of using Visual Studio. When the pairing and iOS 8 issues has been fixed, I'll come back to this and start a support incident with Xamarin, to get help from one of their engineers on this.

  • Hi @RenGundersen and @michelTol, I am having the same problem. Even the simplest custom control with all the trimmings (based on UIView, implementing IComponent or decorated with DesignTimeVisibleAttribute) does not show up on the Toolbox. Have either of you gotten any further with this?

  • @henniegottenbos‌ and @michelTol‌: I was at a Xamarin conference today and asked Michael James from Xamarin about this problem. He told me that Xamarin had pushed a change in how custom controls worked with the iOS Designer. You can see a note about this in the Xamarin 3.7 release notes

    There's also a note about it in the release notes for Xamarin Studio 5.5.

    The note says that one should implement System.ComponentModel.IComponent or decorate ones custom control with [DesignTimeVisible(true)].
    In my example above, I have the DesignTimeVisible attribute, but I haven't tried the IComponent interface. So I'll try this and see if it works. I'll report back here with my findings.

  • notme.8480notme.8480 USMember

    Im experiencing the same problem. Im using the step-by-step example from the xamarin site but the created control does not show up in the toolbox. Im at Xamarin 5.5.3 build 6 (in iOS 10.9.5) and i use the following code (and variations of it with/without disigntimevisible and/or IComponent.):

    [Register("ViewClass"), DesignTimeVisible(true)]
    public class ViewClass : UIView, System.ComponentModel.IComponent
    {
    public event EventHandler Disposed;

        public ISite Site {
            get;
            set;
        }
    
        public ViewClass ()
        {
            BackgroundColor = UIColor.Yellow;
        }
    
        public ViewClass (IntPtr handle) : base(handle)
        {
            BackgroundColor = UIColor.Purple;   
        }   
    }
    
  • CorradoCavalliCorradoCavalli ITInsider, University ✭✭

    Sounds like a bug to me, added both IComponent and DesignTime attribute, control appears in Xamarin Studio but not on Visual Studio's toolbox.

  • PatrickLongPatrickLong USMember ✭✭

    Is this "Yet Another Xamarin Studio" only feature?

  • KMullinsKMullins USMember, Xamarin Team Xamurai

    Hi All,

    Sounds like you might have found a bug in the iOS Designer. Can I get you to please file a Bugzilla report (or attach to an existing one) agains the iOS Designer.

    Thanks,

    Kevin

  • Just to close the loop for anyone else ending up here, this is the link to the related bug on BugZilla:
    https://bugzilla.xamarin.com/show_bug.cgi?id=18684

  • @KMullins Were you guys able to make any progress on this one, and do you have an idea as to when a fix might be released?

  • dikogadikoga USMember ✭✭

    I am experiencing it either.

    On the other hand, I am not able to add a custom control on Xamarin Studio too. I've done the exactly the first example on this page, on a brand new project it works but on my existing project it doesn't.

    Is there any problems to use it together with PCL's? The custom component is not developed into a PCL, the PCL has been only referred on my main project.

  • Thibault_VellicusThibault_Vellicus CHUniversity ✭✭

    Same thing for me.
    With a new project and a copy of the controls & storyboard -> it works.
    Adding a reference to my PCL project -> it works.

    Copying all files from older project to new project -> doesn't work anymore :-(

    Copying storyboard from new project (with the control) to buggy project -> doesn't work in the designer but when I start the application, it works on the app!

  • Thibault_VellicusThibault_Vellicus CHUniversity ✭✭

    It works perfect with VS2013!
    I hope that somebody from Xamarin Team will fix this bug in Xamarin Studio...

  • VikasShriyanVikasShriyan USMember

    Hi,

    I was going through the following blog
    http://blog.xamarin.com/creating-beautiful-ios-controls-with-paintcode/
    and following the steps. When I build the file, 'DesignTimeVisible(true)' doesn't seem to work.

  • AlanMcGovernAlanMcGovern USXamarin Team Xamurai

    The issue in Xamarin Studio has been fixed and will ship at some stage in the future. I don't know when other than it'll probably be part of the next major release.

This discussion has been closed.