[英]Problem with navigating to another view xamarin community toolkit
I have a problem while trying to navigate to another view from community toolkit popup.我在尝试从社区工具包弹出窗口导航到另一个视图时遇到问题。 It simply wont navigate to new page, instead after clicking button nothing happens.
它只是不会导航到新页面,而是在单击按钮后没有任何反应。
Code:代码:
private async void Btn_Clicked_UpdateAlbum(object sender, EventArgs e)
{
string newalbumname = albumname.Text;
Preferences.Set("NewAlbumName", newalbumname);
await Navigation.PushModalAsync(new ChosePhotosAlbum());
}
I'm using我在用着
packages\xamarin.communitytoolkit\2.0.5\
包\xamarin.communitytoolkit\2.0.5\
You can return a value from your PopUp to the page that opened it, and based on the return value, you can handle whether or not to navigate to another page in your calling page code.您可以从 PopUp 返回一个值到打开它的页面,并且根据返回值,您可以在调用页面代码中处理是否导航到另一个页面。
Below is a sample of a popup returning a bool
, when true navigate to page ChoosePhotosAlbum
.下面是一个返回
bool
的弹出窗口示例,当 true 导航到页面ChoosePhotosAlbum
时。
MainPage.xaml.cs MainPage.xaml.cs
<?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:xct="http://xamarin.com/schemas/2020/toolkit"
x:Class="PopApp1226.MainPage">
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Welcome to Main Page" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<Button Text="popup" Clicked="Button_Clicked" />
</StackLayout>
</ContentPage>
MainPage.xaml.cs MainPage.xaml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void Button_Clicked(object sender, EventArgs e)
{
var result = await App.Current.MainPage.Navigation.ShowPopupAsync(new SimplePopup());
bool returnvalue = false;
if (result is bool)
returnvalue = (bool)result;
if (returnvalue) {
await Navigation.PushModalAsync(new ChoosePhotosAlbum());
}
}
}
SimplePopup.xaml.cs SimplePopup.xaml.cs
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SimplePopup : Popup
{
public SimplePopup()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Dismiss(true);
}
}
SimplePopup.xaml SimplePopup.xaml
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
x:Class="PopApp1226.SimplePopup">
<StackLayout>
<Label Margin="20"
FontSize="15"
Text="SimplePopup"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
<StackLayout Orientation="Horizontal">
<Button Margin="20"
CornerRadius="20"
Text="test"/>
<Button Margin="20"
CornerRadius="20"
Text="Yes"
Clicked="Button_Clicked"/>
</StackLayout>
</StackLayout>
</xct:Popup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.