簡體   English   中英

當標簽欄(底部欄)項目在 xamarin 表單中點擊時,如何僅打開彈出窗口而不是頁面?

[英]How to open popup only instead of page when tab bar (bottom bar) item tap in xamarin forms?

每當我們單擊選項卡欄(底部欄)的任何項目時,我只想打開彈出窗口而不是整個頁面。 彈出窗口將在任何先前選擇的標簽欄項目上打開。 例如我們有 5 個標簽欄項目。

  • tb 項目 1 (Page1)
  • tb 項目 2 (Page2)
  • tb item 3(沒有頁面,只有彈出窗口)
  • tb 第 4 項(第 4 頁)
  • tb 第 5 項(第 5 頁)

如果我在 tb item 1 (Page1) 上並單擊 tb item 3,它將在 tb item 1 (Page1) 上打開彈出窗口。

在此處輸入圖片說明

檢查了這個插件,但它不允許這樣做。

默認情況下, TabbedPage應將頁面作為子頁面。 我假設您想在點擊 tb 項目 3 時保持在同一頁面上。 是tb item 1 tb item 2 tb item 4 ...

取而代之的是,您可以在頁面底部創建一個帶有 5 個圖標的頁面。 並包括所有 5 個項目的 OnTapped 手勢,項目 3 調用 Pop up ,而其他人則導航到相應的頁面。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="App1.Views.PageX">
    <ContentPage.Content>
        <StackLayout>
            <StackLayout VerticalOptions="FillAndExpand">
                <Label Text="Page content" />
            </StackLayout>
            <Grid VerticalOptions="End">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ImageButton Source="tab_feed.png"
                             Grid.Column="0"
                             Clicked="ImageButton1_Clicked" />
                <ImageButton Source="tab_feed.png"
                             Grid.Column="1"
                             Clicked="ImageButton2_Clicked" />
                <ImageButton Source="tab_feed.png"
                             Grid.Column="2"
                             Clicked="ImageButton3_Clicked" />
                <ImageButton Source="tab_feed.png"
                             Grid.Column="3"
                             Clicked="I mageButton4_Clicked" />
                <ImageButton Source="tab_feed.png"
                             Grid.Column="4"
                             Clicked="ImageButton5_Clicked" />
            </Grid>
        </StackLayout>
    </ContentPage.Content>

和頁面導航

private async void ImageButton1_Clicked (object sender, EventArgs e) 
{
    await Navigation.PushAsync (new ItemPage1 ());
}

用於彈出

private async void ImageButton3_Clicked(object sender, EventArgs e)
{
    await Rg.Plugins.Popup.Contracts.IPopupNavigation.PushAsync(new MyPopupPage(), true);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM