Custom controls in Xamarin Previewer not showing

purplehazepurplehaze GBMember ✭✭

HI

I'm trying to do something extremely simple that just isn't working and I can't find anything online to help.

I've got an iOS project in Xamarin Forms and I'm trying to create a StackLayout with custom controls in it. Each custom control is effectively a message, so (even though it's not), imagine something like WhatsApp where each message is a custom control. I've been trying to ages to try and see my custom control in the previewer (I've got a slight layout issue that I'm trying to resolve and I'd like to see my controls in the Previewer).

So to try and simplify it, I've created a bare bones BoxView custom control like this:

<?xml version="1.0" encoding="UTF-8"?>
<BoxView xmlns="http://xamarin.com/schemas/2014/forms"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     x:Class="Mk.Views.ClassNews.MyView" BackgroundColor="Gray">
</BoxView>

And the code behind looks like this:

using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace Mk.Views.ClassNews
{
    public partial class MyView : BoxView
    {
        public MyView()
        {
            InitializeComponent();
        }
    }
}

In the Previewer, my custom control looks as it should, just a grey screen. But when I include this custom control in another view's layout (like in a StackLayout for instance) it displays when I run the app, but it shows nothing in the Previewer.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     x:Class="Mk.Views.ClassNews.TestPage"
             xmlns:cs="clr-namespace:Mk.Views.TestPage">
    <ContentPage.Content>
        <cs:MyView/>
    </ContentPage.Content>
</ContentPage>

And the code behind:

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Mk.Views.ClassNews
{
    public partial class TestPage : ContentPage
    {
        public TestPage()
        {
            InitializeComponent();
        }
    }
}

Running the app, the screen goes gray but the Previewer just stays white. Any ideas as to why?

Thanks

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    in Xamarin Previewer

    Previewer never worked right. At least a hundred threads here for that.
    Custom controls is just one of the numerous shortcoming of that (now dead) project.

  • purplehazepurplehaze GBMember ✭✭
    Thanks for responding. Is there anything equivalent available?
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Equivalent?
    Sure plenty of previewers that don't work.
    :lol:

    In all seriousness - there aren't any good XAML previewers out there. And after a month of working with XAML you get used to it and really don't need it anyway. In the end, if you're code is simple enough for previewer to handle it then you don't need the previewer anyway. If its complex enough to need the previewer, its not going handle your markup and you need to run it on a physical device. Not what new-to-XAML developers want to hear, I know. But its the reality of it.

  • VovaKamishnikovVovaKamishnikov USMember ✭✭✭
    edited May 23

    @purplehaze said:
    Thanks for responding. Is there anything equivalent available?

    LiveXAML works like a charm and saves a lot of time

  • jezhjezh Member, Xamarin Team Xamurai

    Yes, it is just the case for Xamarin Previewer. And we apologize for the inconvenience.
    The xamarin development team is doing their best to address this issue and we are urging them to release the latest version as soon as possible.

    Of course, you can also try other alternate tools ,e.g. LiveXAML and Xamarin live reload

    For more details, you can check:
    https://www.livexaml.com/
    https://marketplace.visualstudio.com/items?itemName=Xamarin.XamarinLiveReload

    Hope it can help you.
    Best Regards.

  • purplehazepurplehaze GBMember ✭✭

    Thanks for all the responses - I'll check out livexaml

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭

    @purplehaze keep in mind, that there is FREE alternative https://github.com/AndreiMisiukevich/HotReload

  • GanesanVGGanesanVG INMember ✭✭

    @purplehaze , Thanks for responding. Is there anything equivalent available?

    For render the custom control, you can try the Gorilla player,
    https://grialkit.com/gorilla-player/

  • purplehazepurplehaze GBMember ✭✭
    Thanks for the info guys, I’ll try them out. Annoying at the moment, I seem to have lost my intellisense for xaml so just trying to work out how to get that back.
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @purplehaze said:
    I seem to have lost my intellisense for xaml so just trying to work out how to get that back.

    Spend the money on ReSharper - The vast improvement over intellisense and code improvement suggestions alone is so worth it. Its like ...what... 20 cents a day if you divide up the cost. You can't tell me your aggravation isn't worth 20 cents.

Sign In or Register to comment.