title: Xamarin passing list item value, from one class to MainPage class ToolbarItem
body: <p>Many hours I am trying to pass ItemSelected value to my MainPage ToolbarItem <code>x:name="CityClick"</code>. This is my code of Cities class and City class behind of Cities class:</p>
  
  <pre><code>public partial class Cities : ContentPage
      {
          private Action&lt;object, SelectedItemChangedEventArgs&gt; onItemSelected;
          public Cities()
          {
              InitializeComponent();
              Label header = new Label
              {
                  Text = "Select here",
                  FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                  HorizontalOptions = LayoutOptions.Center
              };
              List&lt;City&gt; cities = new List&lt;City&gt;
              {
                  new City("C1"),
                  new City("City2")
              };
              ListView listView = new ListView
              {
                  ItemsSource = cities,
                  ItemTemplate = new DataTemplate(() =&gt;
                  {
                      Label nameLabel = new Label();
                      nameLabel.SetBinding(Label.TextProperty, "Name");
                      BoxView boxView = new BoxView();
                      return new ViewCell
                      {
                          View = new StackLayout
                          {
                              Padding = new Thickness(0, 5),
                              Orientation = StackOrientation.Horizontal,
                              Children =
                              {
                                  ...
                              }
                          }
                      };
                  })
              };
              this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
              this.Content = new StackLayout
              {
                  Children =
                  {
                      ..
                  }
              };
              listView.ItemSelected += async (sender, e) =&gt;
              {
                  if (e.SelectedItem == null)
                  {
                      return;
                  }
                  else
                  {
                      await Navigation.PopAsync();
                  }
  
              };
          }
          public Cities(Action&lt;object, SelectedItemChangedEventArgs&gt; onItemSelected)
          {
              this.onItemSelected = onItemSelected;
          }
      }
      public class City
      {
          public City()
          {
              this.Name = Name;
          }
          public City(string name)
          {
              this.Name = name;
          }
          public string Name { set; get; }
      };
  </code></pre>
  
  <p>This is my MainPage class where I initialize City() class, but when I am debugging it shows null for obj.Name :</p>
  
  <pre><code>public partial class MainPage : MasterDetailPage
      {
          public MainPage()
          {
              InitializeComponent();
              masterPage.ListView.ItemSelected += OnItemSelected;
  
              CityClick.Clicked += async (sender, e) =&gt;
              {
                  await Detail.Navigation.PushAsync(new Cities());
              };
              City obj = new City();
              Cities obj2 = new Cities();
              var myobject = Application.Current.Properties[CityClick.Text];
              myobject = obj.Name;
              if (obj.Name == null)
              {
                  if (Application.Current.Properties.ContainsKey(CityClick.Text))
                  {
                      var id = Application.Current.Properties[CityClick.Text] as string;
                      CityClick.Text = obj.Name;
                  }
              }
          }}
  </code></pre>
  
  <p>And this is MainPage xaml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    xmlns:local="clr-namespace:LearningProject;assembly=LearningProject"
                    x:Class="LearningProject.MainPage"
            MasterBehavior="Popover"&gt;
    &lt;ContentPage.ToolbarItems&gt;
      &lt;ToolbarItem x:Name="CityClick"
                   Text="City:"
                   Order="Primary"&gt;
      &lt;/ToolbarItem&gt;
    &lt;/ContentPage.ToolbarItems&gt;
    &lt;MasterDetailPage.Master&gt;
      &lt;local:MasterPage x:Name="masterPage" /&gt;
    &lt;/MasterDetailPage.Master&gt;
    &lt;MasterDetailPage.Detail&gt;
      &lt;NavigationPage&gt;
        &lt;x:Arguments&gt;
          &lt;local:UnpaidVehicle /&gt;
        &lt;/x:Arguments&gt;
      &lt;/NavigationPage&gt;
    &lt;/MasterDetailPage.Detail&gt;
  &lt;/MasterDetailPage&gt;
  </code></pre>
  
  <p>So when I am debuging, it is shows that ItemSelected hold some string name. But when I am debuging MainPage.xaml.cs it shows that it is null. Why obj.Name do not reach value from Cities class?</p>