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