0

I'm new to Xamarin/Visual Studio For Mac(Preview). I'm not new to C#. Im struggling with how to get a SearchBar in the header.

Im using the Xamarin.CRM Sample from the Xamarin Website.

It looks like theres a ViewModel that is binding the title to the header of each page but I would rather have a search bar.

XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Phoodie.AboutPage" xmlns:vm="clr-namespace:Phoodie;" Title="{Binding Title}">
<ContentPage.BindingContext>
    <vm:AboutViewModel />
</ContentPage.BindingContext>

Code Behind

public partial class ItemsPage : ContentPage
{
    ItemsViewModel viewModel;

    public ItemsPage()
    {
        InitializeComponent();

        BindingContext = viewModel = new ItemsViewModel();
    }

    async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
    {
        var item = args.SelectedItem as Item;
        if (item == null)
            return;

        await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));

        // Manually deselect item
        ItemsListView.SelectedItem = null;
    }

    async void AddItem_Clicked(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new NewItemPage());
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        if (viewModel.Items.Count == 0)
            viewModel.LoadItemsCommand.Execute(null);
    }
}

ViewModel

public ItemsViewModel()
    {
        Title = "Browse";
        Items = new ObservableRangeCollection<Item>();
        LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());

        MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
        {
            var _item = item as Item;
            Items.Add(_item);
            await DataStore.AddItemAsync(_item);
        });
    }

What I'm trying to accomplish

enter image description here

THANK YOU FOR YOUR HELP AHEAD OF TIME!

Lex Li
  • 60,503
  • 9
  • 116
  • 147
scouty
  • 145
  • 1
  • 10

0 Answers0