Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Regarding Back Problem in master details page

$
0
0

I am facing issues with on pressing the back button, my application get closed.
actually i want to create a menu with hamburger icon that will display to all the application using master details page.
but when i am going to next page and return back to the same page my application gets closed.

My Code are below

xaml code:
<MasterDetailPage.Master>
<ContentPage
Icon="hamburger_menu.png"
Title="Menu"

            BackgroundColor="#3D3C42">

        <!-- Menu Title background color -->

        <!-- Slide out Menu -->
        <StackLayout VerticalOptions="FillAndExpand" HeightRequest="150">
            <StackLayout VerticalOptions="FillAndExpand" HeightRequest="150">
                <Label x:Name="lblspace" 
                Text="" 
                TextColor="White" 
                FontSize="12" 
                VerticalOptions="Center" 
                HorizontalOptions="Center" />
                <controls:CircleImage x:Name="userimage" Source="defaultImageMale.png"
                        HeightRequest="100"
                        HorizontalOptions="Center"
                        BorderThickness="1"
                        BorderColor="#5d5d6a"
                        Aspect="AspectFill"
                        WidthRequest="100"                     
                        />
                <Label x:Name="lblusername" 
                Text="Menu" 
                TextColor="White" 
                FontSize="12" 
                VerticalOptions="Center" 
                HorizontalOptions="Center"               
                Margin="0, 27, 0, 5" />
            </StackLayout>

            <ListView 
                    x:Name="MenuListView"
                    ItemsSource="{Binding MainMenuItems}"
                    ItemSelected="MainMenuItem_Selected"
                    VerticalOptions="FillAndExpand" 
                    SeparatorVisibility="None" 
                    BackgroundColor="#f5f5f5">
                <!-- Menu background color -->
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ImageCell 
                            Text="{Binding Title}" 
                            ImageSource="{Binding Icon}"
                            TextColor="Black"/>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>

    </ContentPage>
</MasterDetailPage.Master>

**HomePage.xaml.c:smile:
public List MainMenuItems { get; set; }

MainMenuItems = new List()
{
new MainMenuItem() { Title = "Home", Icon = "menu_inbox.png", TargetType = typeof(Dashboard) },
new MainMenuItem() { Title = "Request", Icon = "menu_inbox.png", TargetType = typeof(requestAsset) },
new MainMenuItem() { Title = "My Items", Icon = "menu_stock.png", TargetType = typeof(MyItems) },
new MainMenuItem() { Title = "Consume", Icon = "menu_inbox.png", TargetType = typeof(Consume) },
new MainMenuItem() { Title = "Return", Icon = "menu_stock.png", TargetType = typeof(Return) },
new MainMenuItem() { Title = "Replacement", Icon = "menu_stock.png", TargetType = typeof(Replacement) },
new MainMenuItem() { Title = "Transfer", Icon = "menu_inbox.png", TargetType = typeof(Transfer) },
new MainMenuItem() { Title = "Checkout", Icon = "menu_inbox.png", TargetType = typeof(CheckoutRequest) }
};

        // Set the default page, this is the "home" page.
        Detail = new NavigationPage(new Dashboard())
        {
            BarTextColor = Color.White,
            BarBackgroundColor = Color.FromHex("#21212D"),
        };

public void MainMenuItem_Selected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MainMenuItem;
if (item != null)
{
if (item.Title.Equals("Home"))
{
// Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));

                Detail = new NavigationPage(new Dashboard())
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            if (item.Title.Equals("Request"))
            {
                Detail = new NavigationPage(new requestAsset(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };

                //Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType, "")) {
                //    BarTextColor = Color.White,
                //    BarBackgroundColor = Color.FromHex("#21212D"),
                //};
            }
            else if (item.Title.Equals("My Items"))
            {
                //Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
                Detail = new NavigationPage(new MyItems())
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            else if (item.Title.Equals("Consume"))
            {
                Detail = new NavigationPage(new Consume(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            else if (item.Title.Equals("Return"))
            {
                Detail = new NavigationPage(new Return(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            else if (item.Title.Equals("Replacement"))
            {
                Detail = new NavigationPage(new Replacement(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            else if (item.Title.Equals("Transfer"))
            {
                Detail = new NavigationPage(new Transfer(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }
            else if (item.Title.Equals("Checkout"))
            {
                Detail = new NavigationPage(new CheckoutRequest(""))
                {
                    BarTextColor = Color.White,
                    BarBackgroundColor = Color.FromHex("#21212D"),
                };
            }

            MenuListView.SelectedItem = null;
            IsPresented = false;
        }
    }

Please help i am getting stuck into this from last two days


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>