diff --git a/src/Controls/samples/Controls.Sample/Pages/Base/BasePage.cs b/src/Controls/samples/Controls.Sample/Pages/Base/BasePage.cs index a410f211ba2a..daafec4b035e 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Base/BasePage.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Base/BasePage.cs @@ -9,12 +9,18 @@ namespace Maui.Controls.Sample.Pages.Base { public class BasePage : ContentPage, IPage { + SectionModel _selectedItem; + public BasePage() { - NavigateCommand = new Command(sectionModel => + NavigateCommand = new Command(async () => { - if (sectionModel != null) - Navigation.PushAsync(PreparePage(sectionModel)); + if (SelectedItem != null) + { + await Navigation.PushAsync(PreparePage(SelectedItem)); + + SelectedItem = null; + } }); } @@ -30,6 +36,16 @@ protected override void OnDisappearing() public ICommand NavigateCommand { get; } + public SectionModel SelectedItem + { + get { return _selectedItem; } + set + { + _selectedItem = value; + OnPropertyChanged(); + } + } + Page PreparePage(SectionModel model) { var page = (Page)Activator.CreateInstance(model.Type); diff --git a/src/Controls/samples/Controls.Sample/Pages/CompatibilityPage.xaml b/src/Controls/samples/Controls.Sample/Pages/CompatibilityPage.xaml index 3c9cec94ff31..ca7e8b19b15f 100644 --- a/src/Controls/samples/Controls.Sample/Pages/CompatibilityPage.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/CompatibilityPage.xaml @@ -46,8 +46,8 @@ BackgroundColor="Transparent" ItemsSource="{Binding FilteredItems}" SelectionMode="Single" + SelectedItem="{Binding SelectedItem, Source={x:RelativeSource AncestorType={x:Type ContentPage}}, Mode=TwoWay}" SelectionChangedCommand="{Binding NavigateCommand, Source={x:RelativeSource AncestorType={x:Type ContentPage}}}" - SelectionChangedCommandParameter="{Binding SelectedItem, Source={x:Reference CompatibilitySections}}" Margin="6, 12, 6, 0"> + Margin="6, 12, 6, 0">