Windows 스토어 앱 XAML-탐색 된 페이지의 텍스트 상자 값을 가져 오는 방법. 2 페이지가 있습니다. 1. MainPage.xaml 2. Infopage.xaml이 MainPage에 있습니다. Button (InfoPage의 TextBox 값을 가져 오기 위해)과 프레임 (InfoPage를 탐색하기 위해)이 있습니다. ) .. InfoPage에는 몇 가지 TextBoxes가 있습니다. 이제 InfoPage TextBox 값을 어떻게 얻을 수 있습니까?
Neal의 솔루션 외에도 참조 할 수있는 또 다른 두 가지 방법이 있습니다.
한 가지 방법은 정적 매개 변수를 정의 infoPage
하고 값을 현재 페이지로 설정하는 것입니다. 그런 다음에 메소드 호출 할 수 있습니다 infoPage
에서를 MainPage
. 다음과 같은 코드 :
infoPage
public static InfoPage Current;
public InfoPage()
{
this.InitializeComponent();
Current = this;
}
public string gettext()
{
return txttext.Text;
}
MainPage
private void btngetsecondpage_Click(object sender, RoutedEventArgs e)
{
InfoPage infopage = InfoPage.Current;
txtresult.Text = infopage.gettext();
}
자세한 내용은 공식 샘플을ApplicationData
참조하십시오 .
또 다른 방법은 ApplicationData.LocalSettings 에 임시 텍스트를 저장 infoPage
하고 MainPage
. 다음과 같은 코드 :
infoPage
private void txttext_TextChanged(object sender, TextChangedEventArgs e)
{
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values["texboxtext"] =txttext.Text; // example value
}
MainPage
private void btngetsecondpage_Click(object sender, RoutedEventArgs e)
{
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
if (localSettings.Values["texboxtext"] != null)
{
txtresult.Text = localSettings.Values["texboxtext"].ToString();
}
}
많은 양의 데이터가있는 경우 더 좋은 방법은 로컬 파일을 데이터베이스로 만들고 MVVM 패턴을 사용 infoPage
하여 데이터베이스에 저장된 데이터를 MainPage
. uwp의 MVVM에 대한 자세한 내용은 이 기사를 참조 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다