Forum Visual Studio

Using DesignInstance in XAML produces an error in VS but runs correctly

I'm working on a Xamarin Forms application that sets the BindingContext of my views in code. I was looking for ways to setup my XAML so that it would autocomplete properties from my ViewModels. I had been using some hack solution for this until I recently came across an article that described using the DesignInstance attribute. This works great except that Visual Studio reports the attribute as an error. In the Error List the description is:

MarkupExtension not found for d:DesignInstance (there is no error code for this error)

If I go to the XAMl file and hover over the error the description there is:

The type 'd:DesignInstance' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built

The strange part is that despite these errors my application runs fine. My question is: Is there anyway to ignore or fix this error?

In the short term it's mostly just an annoyance but I'm worried about using this in the future with automated builds. I could see this causing the builds to fail when really they are fine.

MySuperAwesomeView.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:viewModels="clr-namespace:My.Namespace.ViewModels"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance viewModels:MySuperAwesomeViewModel}"
             x:Class="My.Namespace.Views.MySuperAwesomeView">
    <ContentPage.Content>
        <!-- My content -->
    </ContentPage.Content>
</ContentPage>

Answers

Sign In or Register to comment.