gpt4 book ai didi

c# - 获取在 ContentPage 中更改的 int 的结果

转载 作者:行者123 更新时间:2023-11-30 18:15:53 26 4
gpt4 key购买 nike

我有一个具有以下页面结构的应用程序:

MainPage
->SettingsPage
->InputLanguagePage
->OutputLanguagePage

所有页面都是内容页面。

InputLanguagePage 和 OutputLanguagePage 是完全相同的页面,所以我不想对相同的页面进行两次编程。

我当然可以实例化同一个页面两次,但我不知道我应该如何获得返回值。

我花了很长时间试图描述我的问题。也许下面的代码可以更好地说明问题。

如您所见,我似乎无法获取 LanguageSelectionPage 的返回值,因为它显示为异步。将其更改为 Navigation.PushModalAsync() 也没有任何改变。

让 ContentPage 返回值或更改值并收到相关通知的最佳方式是什么?

谢谢。

主页:

public class MainPage : ContentPage
{
private async void OnSettingsSelected(object sender, EventArgs e)
{
SettingsPage nSettings = new SettingsPage();
await this.Navigation.PushAsync(nSettings);
}
(...)

设置页面:

public class SettingsPage : ContentPage
{
public SettingsPage()
{
protected override async void OnAppearing()
{
base.OnAppearing();

_btnInputLanguage.Clicked += async (sender, e) =>
{
LanguageSelectionPage nInputLanguage = new LanguageSelectionPage();
nInputLanguage.SelectedLCID = App.Settings.InputLanguageLCID;
await Navigation.PushAsync(nInputLanguage);
//The user can change "int SelectedLCID" within the ContentPage, but I have no idea how I could access it
return;
};

_btnOutputLanguage.Clicked += async (sender, e) =>
{
LanguageSelectionPage nOutputLanguage = new LanguageSelectionPage();
nOutputLanguage.SelectedLCID = App.Settings.OutputLanguageLCID;
await Navigation.PushAsync(nOutputLanguage);
//The user can change "int SelectedLCID" within the ContentPage, but I have no idea how I could access it
return;
};

(...)

语言选择页面:

public class LanguageSelectionPage : ContentPage
{
public int SelectedLCID { get; set; }

protected override async void OnAppearing()
{
base.OnAppearing();

(...)

最佳答案

当你要求加载页面时,我会给solutin传递ass参数

public partial class InputLanguagePage : ContentPage
{
public InputLanguagePage(string Selection)
{
InitializeComponent();
}
}

public partial class OutputLanguagePage : ContentPage
{
public OutputLanguagePage(string Selection)
{
InitializeComponent();
}
}

在设置页面按钮点击

_btnInputLanguage.Clicked += async (sender, e) =>
{
Navigation.PushAsync(new InputLanguagePage ("SelectLanguage"));
return;
};

_btnOutputLanguage.Clicked += async (sender, e) =>
{
Navigation.PushAsync(new OutputLanguagePage("SelectLanguage"));
return;
};

关于c# - 获取在 ContentPage 中更改的 int 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47503083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com