locked
Custom control not showing up in toolbox RRS feed

  • Question

  • User51510 posted

    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?

    Friday, October 17, 2014 11:06 AM

All replies

  • User50 posted

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

    Friday, October 17, 2014 7:39 PM
  • User51510 posted

    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.

    Saturday, October 18, 2014 8:29 AM
  • User51510 posted

    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.

    Saturday, October 18, 2014 9:08 AM
  • User77819 posted

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

    Tuesday, October 21, 2014 12:50 PM
  • User51510 posted

    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.

    Tuesday, October 21, 2014 1:06 PM
  • User666 posted

    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?

    Tuesday, November 4, 2014 6:39 PM
  • User51510 posted

    @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.

    Monday, November 10, 2014 9:08 PM
  • User82784 posted

    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;   
        }   
    }
    
    Friday, November 14, 2014 2:50 PM
  • User3066 posted

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

    Saturday, December 27, 2014 10:04 AM
  • User62427 posted

    Is this "Yet Another Xamarin Studio" only feature?

    Friday, January 23, 2015 2:21 PM
  • User31231 posted

    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

    Friday, January 23, 2015 4:42 PM
  • User49629 posted

    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

    Monday, February 9, 2015 7:53 PM
  • User49629 posted

    @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?

    Monday, February 9, 2015 7:58 PM
  • User91545 posted

    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.

    Friday, February 27, 2015 4:57 PM
  • User4136 posted

    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!

    Wednesday, May 6, 2015 4:11 PM
  • User4136 posted

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

    Wednesday, May 6, 2015 4:19 PM
  • User137423 posted

    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.

    Tuesday, June 23, 2015 10:02 PM
  • User1148 posted

    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.

    Tuesday, June 23, 2015 11:32 PM