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.
Answers
@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.
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
Below is XAML code
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
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;
}
}
}
}
can you please answer my question? I have also tried the XAMLSample provided by you. Getting same error. Please help
@GagaMisha can you share your project to us?
@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
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"
Thanks @XofoSol !!! that worked for me
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
<?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>
nevermind got it working. I changed the namespace of the Video Player
@XofoSol THanks !!!
It works for me too