,当我在调用选择器并选择了值并按下硬件后退按钮以再次调用该选择器时,页面上有选择器。我尝试禁用后退按钮,但它的选择器被调用。
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed();
return true;
}
但是在此之后,当按下返回按钮选择器时,也会一次又一次地调用
从下面的UserListPicker中检查此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"
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>
答案 0 :(得分:0)
好吧,我认为是因为您正在通过调用base.OnBackButtonPressed
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed(); //Comment this line
return true;
}
由于您在此处返回true,因此无需调用base方法。删除它,看看它是否对您有用
答案 1 :(得分:0)
我遇到了与您描述的问题相同的问题,几个小时后,我发现此错误报告是我的问题:https://github.com/xamarin/Xamarin.Forms/issues/7311
我的解决方案:将Xamarin.Forms插件降级到较旧的版本。如果您不需要最新版本,它应该可以工作。