在框架手势上显示内容视图

时间:2018-10-04 06:25:02

标签: xamarin xamarin.forms

我正在开发使用xaml表单的跨平台应用程序,但尚未弄清楚如何调用ContentView ontapGesture。我可以使用<local:MailRoomList/>在xaml表单上调用ContentView,但是我无法在点击或单击事件时显示视图。

我尝试使用StackLayoutID.Children.Add(new MailRoomList());在stacklayout上显示视图,但这不是我想要的。我想在启用返回按钮的情况下在内容页面上显示完整的contentview。

请告知。谢谢

MailRoomList

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="xx.xxxx.xx.Views.MailRoomList">
<ContentView.Content>
  <StackLayout>
      <Label Text="This is my MailRoom List" />
  </StackLayout>
</ContentView.Content>
</ContentView>

OnTapGesture

<Frame.GestureRecognizers>
    <TapGestureRecognizer Tapped="OnRegisterMail" NumberOfTapsRequired="1"/>
</Frame.GestureRecognizers>

CodeBehind

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

编辑: 主页

<?xml version="1.0" encoding="utf-8" ?>
<xf1:BottomBarPage
         xmlns:xf1="clr-namespace:xx.xxxx.xx.BottomBar" 
         xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:xx.xxxx.xx.Views"
        x:Class="xx.xxxx.xx.Views.Home">
<ContentPage x:Name="MailRoomPage" Title="MailRoom" Icon="mailroom.png" xf1:BottomBarPageExtensions.TabColor="Orange" xf1:BottomBarPageExtensions.BadgeCount="5">
    <local:MailRoom/>
</ContentPage>

<ContentPage Title="Transport" Icon="transport.png" xf1:BottomBarPageExtensions.TabColor="Green" xf1:BottomBarPageExtensions.BadgeCount="10">
    <Label VerticalOptions="Center" HorizontalTextAlignment="Center" Text="Transport" FontSize="Large"/>
</ContentPage>
<ContentPage Title="Communication" Icon="communication.png" xf1:BottomBarPageExtensions.TabColor="Blue" xf1:BottomBarPageExtensions.BadgeCount="3">
    <Label VerticalOptions="Center" HorizontalTextAlignment="Center" Text="Communication" FontSize="Large"/>
</ContentPage>
<ContentPage Title="HSE" Icon="hse.png" xf1:BottomBarPageExtensions.TabColor="Red" xf1:BottomBarPageExtensions.BadgeCount="2">
    <Label VerticalOptions="Center" HorizontalTextAlignment="Center" Text="HSE" FontSize="Large"/>
</ContentPage>
<ContentPage Title="Meeting" Icon="meeting.png" xf1:BottomBarPageExtensions.TabColor="DarkCyan" xf1:BottomBarPageExtensions.BadgeCount="5">
    <Label VerticalOptions="Center" HorizontalTextAlignment="Center" Text="Meeting" FontSize="Large"/>
</ContentPage>

从上面的主页开始,我正在调用视图<local:MailRoom/>,该视图正在调用另一个视图MailRoomList。这是我需要您如何从另一个内容视图调用一个内容视图的建议。

1 个答案:

答案 0 :(得分:0)

ContentViewView而不是Page。将您的MainRoomList Xaml更改为此

 <?xml version="1.0" encoding="UTF-8"?>
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="xx.xxxx.xx.Views.MailRoomList">
     <StackLayout>
        <Label Text="This is my MailRoom List" />
     </StackLayout>
 </ContentPage>

View不支持导航,如果它们属于{strong>包含的对象Page,则只能导航到导航基础结构。

如果您想将MailRoomList保留为ContentView,则需要将其包含在其他页面中,并执行导航(在tap方法内)到该其他页面