简体   繁体   English

Xamarin forms 如何修复导航栏

[英]Xamarin forms how to fix NavBar

I have a problem with Shell.NavBar, the fact is that when I open the Editor, the NavBar is not visible.我对 Shell.NavBar 有问题,事实是当我打开编辑器时,导航栏是不可见的。

My Code Page xaml:我的代码页 xaml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Corporate_messenger.Service"
             x:Class="Corporate_messenger.Views.ChatPage" Shell.BackgroundColor="#04283C" Shell.TitleColor="White" x:Name="set_pqage"  >

   
    <ContentPage.ToolbarItems>
        
        
       
        <ToolbarItem  
            IconImageSource="audioSocket.png" 
            x:Name="VoiceRecord" 
            Clicked="VoiceRecord_Clicked">
        </ToolbarItem>
    </ContentPage.ToolbarItems>

   
    <Shell.BackButtonBehavior>
        <BackButtonBehavior 
            Command="{Binding GoBack}">
        </BackButtonBehavior>
    </Shell.BackButtonBehavior>

    
    <ContentPage.Resources>

        <ResourceDictionary>
          
            <DataTemplate 
            x:Key="FromTemplate">
                <ViewCell 
                x:Name="FromUserCell" 
                IsEnabled="True"  >
                    <ViewCell.View >
                        <FlexLayout 
                            JustifyContent="Start">

                            <Frame 
                            BackgroundColor="#ECEDF1"
                            CornerRadius="14"                          
                            Padding="5,10,10,10"
                            HasShadow="false"               
                            Margin="10,10,40,0">
                                <StackLayout 
                                    Orientation="Horizontal">
                                    <Label 
                                        Text="{Binding Message}" 
                                        IsEnabled="True"                                      
                                        HorizontalTextAlignment="Start"   
                                        TextColor="Black"/>
                                    <ImageButton 
                                        x:Name="LeftPlay" 
                                        Command="{Binding Source={x:Reference MyListView},Path=BindingContext.PlayAudioMessage}" 
                                        CommandParameter="{Binding .}"  
                                        Source="{Binding Path=SourceImage,Mode=TwoWay}"                                         
                                        IsVisible="{ Binding IsAuidoVisible, Mode=TwoWay}"       
                                        WidthRequest="35" HeightRequest="35" 
                                        CornerRadius="50" 
                                        BackgroundColor="#0986CE">
                                    </ImageButton>
                                    <Slider 
                                        x:Name="LeftSlider" 
                                        IsVisible="{Binding IsAuidoVisible, Mode=TwoWay}"
                                        Maximum="{Binding MaximumSlider}" 
                                        Value="{Binding ValueSlider}"
                                        IsEnabled="{Binding IsEnableSlider}" 
                                        MaximumTrackColor="Gray" 
                                        MinimumTrackColor="#41A9FE"                                         
                                        WidthRequest="150">
                                    </Slider>
                                    <Label   
                                        Text="{Binding Time_LstMessage}" 
                                        FontSize="11" MinimumWidthRequest="30" 
                                        VerticalTextAlignment="End" 
                                        HorizontalTextAlignment="End"   
                                        TextColor="DimGray"/>
                                </StackLayout>
                            </Frame>
                        </FlexLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>

            <!--Правый блок сообщений-->
            <DataTemplate 
                x:Key="ToTemplate">
                <ViewCell  
                x:Name="ToUserCell" 
                IsEnabled="True">
                    <FlexLayout 
                    JustifyContent="End" >
                        <Frame                      
                    CornerRadius="14" 
                    BackgroundColor="#CCE4FF"
                    Padding="5,10,10,10"
                    Margin="50,10,20,0"
                    HasShadow="false"      
                    IsClippedToBounds="True">
                            <StackLayout 
                            Orientation="Horizontal">
                                <Label    
                                    Text="{Binding Message}" 
                                    IsVisible="{Binding IsMessageVisible, Mode=TwoWay}"
                                    IsEnabled="True" 
                                    HorizontalTextAlignment="Start"   
                                    TextColor="Black"/>
                                <ImageButton
                                    x:Name="RightPlay"
                                    Command="{Binding Source={x:Reference MyListView},Path=BindingContext.PlayAudioMessage}" 
                                    CommandParameter="{Binding .}"  
                                    Source="{Binding Path=SourceImage,Mode=TwoWay}" 
                                    IsVisible="{ Binding IsAuidoVisible, Mode=TwoWay}" 
                                    WidthRequest="35" 
                                    HeightRequest="35" 
                                    CornerRadius="50" 
                                    BackgroundColor="#0986CE">
                                </ImageButton>

                                <Slider 
                                    Maximum="{Binding MaximumSlider}" 
                                    Value="{Binding ValueSlider}"                                    
                                    IsEnabled="{Binding IsEnableSlider}"                                    
                                    IsVisible="{Binding IsAuidoVisible, Mode=TwoWay}"
                                    WidthRequest="150"  
                                    MaximumTrackColor="Gray" 
                                    MinimumTrackColor="#41A9FE">
                                </Slider>

                                <Label  
                                    Text="{Binding Time_LstMessage}" 
                                    FontSize="11" 
                                    MinimumWidthRequest="30" 
                                    VerticalTextAlignment="End" 
                                    HorizontalTextAlignment="End"   
                                    TextColor="DimGray"/>
                            </StackLayout>
                        </Frame>
                    </FlexLayout>
                </ViewCell>
            </DataTemplate>
            <local:ClassDataTemplateSelector
                x:Key="chatDataTemplateSelector" 
                FromTemplate="{StaticResource FromTemplate}" 
                ToTemplate="{StaticResource ToTemplate}"/>
        </ResourceDictionary>
    </ContentPage.Resources>

  
    <ContentPage.Content>
        <StackLayout >
            
            <ListView
                IsRefreshing="{Binding IsRefreshing}" 
                RefreshCommand="{Binding UpdateList}"
                ItemTemplate="{StaticResource chatDataTemplateSelector}"  
                ItemsSource="{Binding LastMessage}"
                Background="#04283C" 
                IsPullToRefreshEnabled="True" 
                RefreshControlColor="Cyan"  
                Margin="0,0,0,0" 
                SeparatorColor="Transparent"  
                x:Name="MyListView" 
                HasUnevenRows="true" 
                >
            </ListView>

            <Grid 
                RowSpacing="0" 
                ColumnSpacing="0">

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                 <!--Атрибут для написания сообщения-->
                <Editor
                    Text="{Binding Input_message}"  
                    Margin="5,0,0,0"  
                    x:Name="MessageEditor"  
                    Keyboard="Chat" 
                    TextColor="Black" 
                    Placeholder="Введите сообщение..." 
                    AutoSize="TextChanges" 
                    Grid.Row="0" 
                    Grid.Column="0">
                </Editor>
                
             
                <ImageButton
                    Command="{Binding SendMessage}"
                    CommandParameter="{Binding}"
                    Grid.Row="0" 
                    Grid.Column="1" 
                    Source="send_msg.png" 
                    BackgroundColor="Transparent" 
                    WidthRequest="32" HeightRequest="32" 
                    x:Name="send_message"  
                  />

             
                <ImageButton  
                    Pressed="mic_message_Pressed" 
                    Released="mic_message_Released" 
                    Grid.Row="0" 
                    Grid.Column="2" 
                    Source="mic.png" 
                    Padding="0" 
                    BackgroundColor="Transparent"  
                    WidthRequest="32" 
                    HeightRequest="32" 
                    x:Name="mic_message" 
                    Margin="0,0,10,0"/>
            </Grid>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Go to page code: Go 到页面代码:

async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var v = (ChatListModel)e.Item;
            await Navigation.PushAsync(new ChatPage(v.Id, v.Title));
        }

help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls help pls帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助请帮助

Example in pictures: enter image description here图片中的示例:在此处输入图片描述

enter image description here在此处输入图像描述

It looks like this open issue - Shell - Navigation.PushAsync - Navigation Bar ignored on iOS .看起来像这个未解决的问题 - Shell - Navigation.PushAsync - 在 iOS 上忽略导航栏 In there is a comment saying the work-around for now is to set ios:Page.UseSafeArea="true" on each page.有一条评论说现在的解决方法是在每个页面上设置ios:Page.UseSafeArea="true"

<ContentPage
    ...
    xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
    ios:Page.UseSafeArea="true"
    ... >

OR to avoid adding that to every page, make a BaseContentPage class that includes those two lines, then have your pages inherit from BaseContentPage instead of ContentPage .或者为了避免将其添加到每个页面,请制作一个包含这两行的BaseContentPage class,然后让您的页面从BaseContentPage而不是ContentPage继承。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 taskScheduler OnUnobservedException xamarin 表单? - how to fix taskScheduler OnUnobservedException xamarin forms? 在 Xamarin 表单应用程序中使用菜单创建导航栏 - Create Navbar with Menus in Xamarin forms app 如何修复xamarin.forms移动应用页面中的空列表视图 - How to fix an empty listview in xamarin.forms mobile app page 如何修复Xamarin表单构建错误:“无法为类创建JavaTypeInfo” - How to fix Xamarin forms build error: “Failed to create JavaTypeInfo for class” 如何修复Xamarin.Forms条目附加属性“流血”? - How to fix Xamarin.Forms Entry Attach Property “Bleed Over”? 如何解决将通用列表绑定到Xamarin形式的ListView的问题? - How to fix the issue with binding generic list to listview in xamarin forms? 如何修复Xamarin表单中的“打开失败:errno 13”异常 - How to fix “open failed: errno 13” exception in xamarin forms Xamarin表单 - 如何修复破坏的构建? (好像FormsMap打破了它) - Xamarin Forms - how to fix broken build? (seems like FormsMap broke it) 如何修复 GattStatus:3 - BLE Xamarin 表单应用程序的 WriteNotPermitted 异常? - How to fix GattStatus: 3 - WriteNotPermitted exception for BLE Xamarin forms application? 如何在Xamarin中设计表单? - How to design forms in Xamarin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM