когда я нажимаю кнопку выбора оборудования назад вызывается с этой страницы - PullRequest
0 голосов
/ 25 сентября 2019

enter image description here У меня есть средство выбора на странице, когда я вызываю средство выбора и выбрано значение, и нажимаю аппаратную кнопку возврата, чтобы средство выбора вызывалось снова.Я пытался отключить кнопку возврата, но вызывается ее средство выбора.

protected override bool OnBackButtonPressed()
{          
    base.OnBackButtonPressed();
    return true;
}

, но после этого также при нажатии кнопки выбора кнопки назад вызывается снова и снова

проверьте этот файл xaml ниже из этого UserListPickerвызывается при нажатии кнопки назад.

 <?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:material="clr- 
  namespace:XF.Material.Forms.UI;assembly=XF.Material.Forms" 
         x:Class="Test.Views.CommentsPage"
         Icon="ic_message.png"
         BackgroundColor="White"
         Title="Simon">
<NavigationPage.TitleView>
    <StackLayout
        Padding="0,0,0,0"
        HeightRequest="35"
        HorizontalOptions="FillAndExpand"
        Orientation="Horizontal"
        VerticalOptions="Center">
        <ImageButton
            Aspect="AspectFit"
            HorizontalOptions="StartAndExpand"
            Source="ic_check.png"
            BackgroundColor="Transparent"
            Clicked="btnSendClicked">
       </ImageButton>
        <Label Text="Send Comments" TextColor="White" 
         HorizontalOptions="StartAndExpand" FontSize="Large"  />
        <ImageButton
            Aspect="AspectFit"
            HorizontalOptions="EndAndExpand"
            Source="ic_close.png"
            BackgroundColor="Transparent"
            Clicked="btnCloseClicked"
            Padding="0,0,10,0"
            CommandParameter="{Binding .}">
        </ImageButton>
    </StackLayout>
  </NavigationPage.TitleView>
  <ContentPage.Content>
  <StackLayout>
   <StackLayout HeightRequest="60" BackgroundColor="#002343" >
    <Label x:Name="lblPartyName"  HorizontalTextAlignment="Center" 
     TextColor="White" HorizontalOptions="FillAndExpand" 
      VerticalOptions="CenterAndExpand" FontSize="Large"></Label>
        </StackLayout>

        <StackLayout Orientation="Horizontal" Margin="10,5,10,5">
            <Grid HorizontalOptions="FillAndExpand"  RowSpacing="0">  
      <Grid.RowDefinitions>  
      <RowDefinition Height="*"/>
      </Grid.RowDefinitions>  
     <material:MaterialCard BackgroundColor="#F0F0F0" 
                            Padding="5" OutlineColor="Navy"  
                            HasShadow="true" 
                            BorderColor="Navy"  
                            Margin="5" HeightRequest="45">
     <AbsoluteLayout>
     <StackLayout AbsoluteLayout.LayoutBounds="0,1,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="#F0F0F0" >
            <StackLayout Orientation="Horizontal">
            <Label Grid.Row="0" 
                   x:Name="partyNameLbl"  
                   TextColor="Orange"  
                   FontSize="Medium" 
                   FontAttributes="Bold"  />
            <Label Grid.Row="0" Grid.Column="1" 
                   x:Name="amountLbl" 
                   Text="{Binding StringFormat='{0:C0}'}"
                   TextColor="Orange"  
                   FontSize="Medium" 
                   FontAttributes="Bold" 
                   HorizontalOptions="EndAndExpand" />
            </StackLayout>
           </StackLayout>
     </AbsoluteLayout>
    </material:MaterialCard>
        </Grid>
        </StackLayout>
        <StackLayout HeightRequest="30" Margin="10,0,10,0" Orientation="Horizontal">
            <Label  Text="Assigned To:" HeightRequest="25" FontSize="Medium" TextColor="Black" />
            <Label  x:Name="assignedUserNameLbl" HeightRequest="25" FontSize="Medium"  TextColor="Orange"  />
        </StackLayout>
<ScrollView >
        <Grid Padding="5" Margin="10,5,10,5">
            <Grid.RowDefinitions>
             <RowDefinition Height="30"/>  
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="30"/>  
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="30"/>  
             <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
             <!--mitigating Factor-->
                <StackLayout Orientation="Horizontal" Grid.Row="0">      
            <Label Text="Mitigating Factor" 
                   TextColor="Black"  
                   HorizontalOptions="StartAndExpand" 
                   FontSize="Large" />
            <ImageButton Grid.Column="1" 
                         Source="ic_pencil.png"
                         BackgroundColor="White"  
                         HorizontalOptions="EndAndExpand" 
                         VerticalOptions="StartAndExpand"  
                         Aspect="AspectFit" 
                         HeightRequest="25" 
                         Clicked="onMitigatingEditBtnClicked"   />
           </StackLayout>
            <StackLayout Orientation="Horizontal" Grid.Row="1">
            <Image Source="ic_comments.png" 
                   HorizontalOptions="Start"
                   Aspect="AspectFit" 
                   VerticalOptions="StartAndExpand"  />
            <Editor Grid.Column="1" 
                    x:Name="entryMitigatingFactor"  
                    TextColor="Gray"  
                    VerticalOptions="StartAndExpand" 
                    HorizontalOptions="FillAndExpand" 
                    HeightRequest="100" 
                    IsReadOnly="true" />
           </StackLayout>
                <!--Approval Conditions-->
             <StackLayout Orientation="Horizontal" Grid.Row="2">      
            <Label Text="Approval Conditions" 
                   TextColor="Black"  
                   HorizontalOptions="StartAndExpand" 
                   FontSize="Large" 
                   />
            <ImageButton Grid.Column="1" 
                         Source="ic_pencil.png" 
                         BackgroundColor="White" 
                         HorizontalOptions="EndAndExpand"
                         VerticalOptions="StartAndExpand"  
                         Aspect="AspectFit" HeightRequest="25" 
                         Clicked="onApprovalEditBtnClicked"   />
           </StackLayout>

            <StackLayout Orientation="Horizontal" Grid.Row="3">
            <Image Source="ic_comments.png"  
                   HorizontalOptions="Start"
                   Aspect="AspectFit" 
                   VerticalOptions="StartAndExpand"  />
            <Editor Grid.Column="1" 
                    x:Name="entryApproval"  
                    TextColor="Gray" 
                    VerticalOptions="StartAndExpand"
                    HorizontalOptions="FillAndExpand"
                    HeightRequest="100" 
                    IsReadOnly="true" />
           </StackLayout>
                 <!--Comments-->
            <StackLayout Orientation="Horizontal" Grid.Row="4">
            <Label Text="Comments"  
                   TextColor="Black" 
                   HorizontalOptions="StartAndExpand" 
                   FontSize="Large" 
                   VerticalOptions="StartAndExpand" />
            <ImageButton Grid.Column="1"  
                         Source="ic_pencil.png"
                         BackgroundColor="White"
                         HeightRequest="25" 
                         HorizontalOptions="EndAndExpand"
                         Aspect="AspectFit" 
                         VerticalOptions="StartAndExpand"
                         Clicked="onCommentEditClicked"  />
            </StackLayout>
            <StackLayout Orientation="Horizontal" Grid.Row="5">
            <Image Source="ic_comments.png"  
                   HorizontalOptions="Start" 
                   Aspect="AspectFit"  
                   VerticalOptions="StartAndExpand"  />
            <Editor Grid.Column="1" 
                    TextColor="Gray"
                    HorizontalOptions="FillAndExpand" 
                    VerticalOptions="StartAndExpand" 
                    x:Name="entryCommentTxt" 
                    HeightRequest="100"
                    IsReadOnly="true"/>
        </StackLayout>   
        </Grid>
            </ScrollView>
        <StackLayout Orientation="Horizontal" Margin="10,0,10,0"  x:Name="pickerStack">
        <Picker x:Name="userListPicker" 
                HorizontalOptions="FillAndExpand" 
                ItemsSource="{Binding PendingList}"
                SelectedIndexChanged="OnPickerSelectedIndexChanged"  
                SelectedIndex="{Binding id}" 
                ItemDisplayBinding="{Binding shortMobileName}"  
                BackgroundColor="White"  
                Title="Select Action"
                TitleColor="{StaticResource backTitleColor}" >

           </Picker> 
             <Picker x:Name="processStageUserPicker" 
                     IsVisible="false" HorizontalOptions="FillAndExpand" 
                     ItemsSource="{Binding ProcessUserList}" 
                     SelectedIndex="{Binding id}" 
                     ItemDisplayBinding="{Binding userName }"  
                     BackgroundColor="White"
                     Title="Select Action"
                     TitleColor="{StaticResource backTitleColor}" >

           </Picker> 
            </StackLayout>
        <StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" >
            <material:MaterialButton Text="CANCEL" 
                                     AllCaps="false"  
                                     TextColor="Black" 
                                     BackgroundColor="#F0F0F0" 
                                     VerticalOptions="StartAndExpand" 
                                     HorizontalOptions="FillAndExpand" 
                                     ButtonType="Flat" 
                                     PressedBackgroundColor="{StaticResource btnPressedColor}" 
                                     FontAttributes="Bold" 
                                     Clicked="onCancelBtnClicked"/>
            <material:MaterialButton Text="SAVE"  
                                     AllCaps="false" 
                                     TextColor="Black"
                                     BackgroundColor="#F0F0F0" 
                                     VerticalOptions="EndAndExpand"  
                                     HorizontalOptions="FillAndExpand"
                                     ButtonType="Flat"
                                     FontAttributes="Bold" 
                                     PressedBackgroundColor="{StaticResource btnPressedColor}" 
                                     Clicked="onApproveBtnClicked"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal" BackgroundColor="{StaticResource backTitleColor}" HorizontalOptions="FillAndExpand">
            <material:MaterialButton PressedBackgroundColor="{StaticResource btnPressedColor}" 
                                     AllCaps="false"
                                     Text="Message" 
                                     TextColor="White" 
                                     BackgroundColor="{StaticResource backTitleColor}" 
                                     ButtonType="Flat"
                                     FontSize="Medium"
                                     BorderWidth="0" 
                                     VerticalOptions="StartAndExpand" 
                                     HorizontalOptions="StartAndExpand"  />
        </StackLayout>
  </StackLayout>
</ContentPage.Content>

Ответы [ 2 ]

0 голосов
/ 26 сентября 2019

У меня была та же проблема, что и вы, через несколько часов я обнаружил, что эта ошибка является моей проблемой: https://github.com/xamarin/Xamarin.Forms/issues/7311

Мое решение: понизить плагин Xamarin.Forms до более старой версии.Должно работать, если вам не нужна новейшая версия.

0 голосов
/ 25 сентября 2019

Ну, я думаю, что это потому, что вы перезваниваете это состояние, вызывая base.OnBackButtonPressed

protected override bool OnBackButtonPressed()
{          
   base.OnBackButtonPressed(); //Comment this line
   return true;
}

Поскольку вы возвращаете true здесь, нет необходимости вызывать базовый метод.Удалите это и посмотрите, работает ли оно для вас

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...