0

I have tabbed page in XAML document and I want to bind a CurrentPage property to my view model.

Upon compiling, I get an error in my XAML document on column 1, line 1.

When I delete binding, the error is gone.

XAML:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
            xmlns:views="clr-namespace:GitRemote.Views;assembly=GitRemote"
            prism:ViewModelLocator.AutowireViewModel="True"
            x:Class="GitRemote.Views.PublicRepositoryPage"
            CurrentPage="{Binding CurrentTabPage, Mode=OneWayToSource}">

  <views:RepositoryNewsPage Title="News"/>
  <views:FileExplorerPage Title="Code"/>
  <!--<views:CommitsPage/>
  <views:PublicIssuesPage/>-->

</TabbedPage>

ViewModel property:

private Page _currentTabPage;

public Page CurrentTabPage
{
    get { return _currentTabPage; }
    set
    {
        SetProperty(ref _currentTabPage, value);
        MessagingCenter.Send(_currentTabPage, PublicReposCurrentTabChanged);
    }
}

When I bind the Title, it compiles without error.

Yura Babiy
  • 515
  • 7
  • 22
  • @ThePerplexedOne Are you seriously?? Hate people that don't read questions, but eager to close it as soon as possible. – Yura Babiy Dec 05 '16 at 10:56
  • Where in your question can we find any indication that it is different from the "usual" NullReferenceException? Did you try to debug it yourself? – Clemens Dec 05 '16 at 11:58
  • I think the problem is that you are using the binding before having the binding context ready , why dont you set the current page in the codebehind instead of having View code only in the ViewModel? – Ahmad ElMadi Dec 05 '16 at 15:30
  • @Clemens It is not null reference exception, there is no exception thrown. It is in compile time. – Yura Babiy Dec 05 '16 at 19:10
  • @BraveHeart There is Mode = OneWayToSource, it means that my property in view model only sets from binding, and XAML property sets itself. – Yura Babiy Dec 05 '16 at 19:13

0 Answers0