Reputation: 1089
im trying to keep a searchbar for datagrid,so when the user enters certain value in search bar,the datagrid should show only entered value.i installed xamarin.forms.xamarin.i have gone through different example but no luck i did get what iam looking for.Looking forward for positive responce. Thank you
Upvotes: 1
Views: 579
Reputation: 2981
This can be achieved by putting a SearchBar
above a ListView. Binding the Text
value of the SearchBar
to a property in your ViewModel enables you to handle changes to the Text
property by querying the data.
In XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<SearchBar Grid.Row="0" Text="{Binding Filter}" HeightRequest="40" />
<ListView Grid.Row="1" ItemsSource="{Binding Items}" />
</Grid>
In the ViewModel:
public List<MyObject> Items { get; set; }
public string Filter
{
get { return filter; }
set
{
filter = value;
// Apply filter to list of Items here...
}
}
Upvotes: 3