Joe Johnston
Joe Johnston

Reputation: 2936

references in xamarin forms XAML

How would you make a reference in XAML vs code behind? It seems like mrkup:Class="System.Web.UI.HtmlTextWriterTag" in the following snip would work

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ns.proj"
         mrkup:Class="System.Web.UI.HtmlTextWriterTag"
         >
        ...

allowing the following.

    <mrkup:hr/>

I still get the undeclared prefix error.

I have tried backing down the tree to System.Web.UI and made sure I was not using a reserved word like html:xx and it still fails. I must be overlooking something basic or seriously missing a XAML/Xamarin.Forms premise.


Update Edit:

Based on Jason and Diego's input: Intellisense kicked in after typing using xmlns:mrkup="using: resulting in

xmlns:mrkup="clr-namespace:System.Web;assembly=netstandard"

Which is a great start

 <mrkup:UI.HtmlTextWriterTag hr=""/>

Fails with mrkup:UI.HtmlTextWriterTag.hr not found in xmlns clr-Namespace:System.Web;assembly=netstandard

Is it possible that .UI is not in System.Web in .NET Standard 2.0?


Update to the Update:

It appears that UI is NOT in System.Web in .NET Standard 2.0. This is from the System.Web.dll in C:\Program Files (x86)\Microsoft SDKs\NuGetPackagesFallback\NETStandard.Library\2.0.1\build\netstandard2.0\ref

UI is **NOT** in System.Web in .NET Standard 2.0

Upvotes: 1

Views: 596

Answers (1)

Diego Rafael Souza
Diego Rafael Souza

Reputation: 5313

Actually, you have to declare the mrkup prefix before use it.

Just like this:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ns.proj"
             xmlns:mrkup="clr-namespace:System.Web.UI;assembly:dllName">
...
    <mrkup:HtmlTextWriterTag hr="Property Value"/>
...
</ContentPage>

I'm not sure where the namespace ends, so in the snippet above I'm supposing the namespace is System.Web.UI and the class HtmlTextWriterTag and then you have a property hr on it. If the referred namespace is outside the actual project, you have to notice that assembly part of the declaration, but you can ignore it when referring to the class of the same assembly.

You can take a look at the official docs from Microsoft about Declaring Namespaces for Types to get a more detailed information.

Upvotes: 1

Related Questions