Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Using custom view in XAML

$
0
0

Hi,

I have created a class which is in the same namespace (namespace name is also the project name [MyComponents]) as my xaml file. I would like to then use MyCustomControl within the xaml. Simplified example:

MyCustomStuff.MyComponents.MyCustomControl

using Xamarin.Forms;
namespace MyCustomStuff.MyComponents
{
    public class MyCustomControl : ContentView
    {
        public MyCustomControl()
        {
            VerticalOptions = LayoutOptions.FillAndExpand;
            HorizontalOptions = LayoutOptions.FillAndExpand;

            Content = new Label
            {
                Text = "Testing 123"
            };
        }
    }
}

MyCustomStuff.MyComponents.MyOuterXAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage    xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                xmlns:local="clr-namespace:MyCustomStuff.MyComponents;assembly=MyCustomStuff.MyComponents"
                x:Class="MyCustomStuff.MyComponents.MyOuterXaml">
  <local:MyCustomControl></local:MyCustomControl>
</ContentPage>

However, I get the following error:
Xamarin.Forms.Xaml.XamlParseException: Position 6:4. Type MyCustomControl not found in xmlns http://xamarin.com/schemas/2014/forms

I must be doing something blindingly obvious wrong, but I cant seem to spot it. Any ideas?

Thanks!


Viewing all articles
Browse latest Browse all 58056

Trending Articles