简体   繁体   English

导航到另一个视图时出现问题 xamarin 社区工具包

[英]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.

相关问题 Xamarin 社区工具包 InputValidation 连接按钮 - Xamarin Community Toolkit InputValidation connect with button Xamarin 社区工具包弹出MVVM绑定问题 - Xamarin Community Toolkit Popup MVVM Binding Issue UWP 社区工具包中的主详细信息视图 - Master-Details view in UWP Community Toolkit Xamarin 社区工具包 CameraView - 在 Android 上访问 DCIM 文件夹 - Xamarin Community Toolkit CameraView - Access DCIM Folder on Android Xamarin Community Toolkit 输入验证在设置 BindingContext 时为真 - Xamarin Community Toolkit input validation is true when BindingContext is set Xamarin 社区工具包 TouchEffect.Command 在 CollectionView 中不起作用 - Xamarin community toolkit TouchEffect.Command not working in CollectionView Xamarin Community Toolkit 输入验证为真,即使条目为空 - Xamarin Community Toolkit input validation is true even when Entry is empty UWP 社区工具包 - UWP Community Toolkit 如何从弹出消息导航到新页面? 我正在使用 Xamarin 社区工具包弹出窗口 - How do I navigate to a new page from a Popup message? I'm using the Xamarin Community Toolkit Popup 从棱镜中的另一个模块导航到一个模块的视图 - Navigating to a view of a module from another module in prism
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM