Forum Xamarin.Forms

Type Local Not Found In xmlns clr:namespace

GaganMishraGaganMishra USMember ✭✭

Hi Team,

I am trying to implement MVVM example from your tutorial. Now when I am trying to ClockViewModel.cs access from .xaml, I am getting error

I have already tried to get solve this issue from Stackoverflow & other thread but no sucsess. Could you please help me to resolve this issue? I am working on same namespace.

Moreover, examples provided by you not working, so please also let me know from where a beginner should start.

Tagged:

Answers

  • DK90DK90 USMember ✭✭✭

    @GagaMisha I think the ModelClockView.cs or ClockViewModel.cs file is defined in a different namespace as the error shows like "Not found in local -> i.e MyTest". There is a possibility that the code could be in different namespace as you have mentioned that you're reusing the sample code. Try to rename the namespace of the file or change the namespace declaration in the xaml file.

    If that doesn't fix post the Xaml code.

  • GaganMishraGaganMishra USMember ✭✭
    edited April 2017

    No, I am in same namespace, Please find the XAML code as below



    Below is my 'ModelClockView' code

    using System;
    using Xamarin.Forms;
    using System.ComponentModel;

    namespace MyTest
    {
    public class ModelClockView :INotifyPropertyChanged
    {
    DateTime dateTime;
    public event PropertyChangedEventHandler PropertyChanged;
    public ModelClockView()
    {
    this.myDateTime = DateTime.Now;
    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
    this.myDateTime = DateTime.Now;
    return true;
    });
    }
    public DateTime myDateTime
    {
    set
    {
    if (dateTime != value)
    {
    dateTime = value;
    if (PropertyChanged != null)
    {
    PropertyChanged(this, new PropertyChangedEventArgs("DateTime"));
    }
    }
    }
    get
    {
    return dateTime;
    }
    }
    }
    }

    Please let me know what I should do now.

    Thanks
    Gagan

  • GaganMishraGaganMishra USMember ✭✭
    edited April 2017

    Below is XAML code

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    
    xmlns:local="clr-namespace:MyTest;assembly=MyTest" 
    
    x:Class="MyTest.MyTestPage">
    
    <Label Text="{Binding DateTime,StringFormat='{0:T}'}"
    
         FontSize="Large"
    
         HorizontalOptions="Center"
    
         VerticalOptions="Center">
    
    <Label.BindingContext>
    
      <local:ModelClockView />
    
    </Label.BindingContext>
    

    Moreover I am in same namespace. Below is ModelClockView code

    using System;
    using Xamarin.Forms;
    using System.ComponentModel;

    namespace MyTest
    {
    public class ModelClockView :INotifyPropertyChanged
    {
    DateTime dateTime;
    public event PropertyChangedEventHandler PropertyChanged;
    public ModelClockView()
    {
    this.myDateTime = DateTime.Now;
    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
    this.myDateTime = DateTime.Now;
    return true;
    });
    }
    public DateTime myDateTime
    {
    set
    {
    if (dateTime != value)
    {
    dateTime = value;
    if (PropertyChanged != null)
    {
    PropertyChanged(this, new PropertyChangedEventArgs("DateTime"));
    }
    }
    }
    get
    {
    return dateTime;
    }
    }
    }
    }

  • GaganMishraGaganMishra USMember ✭✭

    can you please answer my question? I have also tried the XAMLSample provided by you. Getting same error. Please help

  • rmenezesrmenezes BRMember ✭✭

    @GagaMisha can you share your project to us?

  • thaotmthaotm VNMember

    @GagaMisha: You should show Directory for your code

    xmlns:local="clr-namespace:MyTest;assembly=MyTest

    Must be change to

    xmlns:local="clr-namespace:MyTest.ViewModel;assembly=MyTest

    ViewModel is folder you store handler class

    Hope this help.

  • @thaotm
    I have updated as you suggested xmlns:local but we are unable to solve that issue. Please help me

  • XofoSolXofoSol Member

    I know it's a little late to answer, but I had a similar issue.
    @GagaMisha, Sometimes the assembly declaration gives some troubles. Try to declarate only your namespace, like:
    xmlns:local="clr-namespace:MyTest"

  • ilanolkiesilanolkies ARMember ✭✭

    Thanks @XofoSol !!! that worked for me :smiley:

  • nefgrixisnefgrixis Member ✭✭

    This didn't work for me. unfortunately I'm using the VideoPlayer example in the Xamarin docs and it doesn't find the VideoPlayer. I made controls and referenced them the same way with no problem. Not sure what is happening

  • nefgrixisnefgrixis Member ✭✭

    <?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="BizPass.TestPage" xmlns:video="clr-namespace:FormsVideoLibrary"> <ContentPage.Content> <StackLayout HorizontalOptions="Fill" VerticalOptions="Fill"> <video:VideoPlayer Source="https://storage.googleapis.com/coverr-main/mp4/The-Launch.mp4"/> </StackLayout> </ContentPage.Content> </ContentPage>

  • nefgrixisnefgrixis Member ✭✭

    nevermind got it working. I changed the namespace of the Video Player

  • rizkidwiprizkidwip Member ✭✭

    @XofoSol THanks !!!
    It works for me too

Sign In or Register to comment.