저는 Xamarin 을 처음 접 했고 편집기의 텍스트를 기본 페이지에 저장 한 다음 두 번째 페이지에 표시하는 방법을 찾고 있습니다. 그렇게 어려울 수는 없지만 해결책을 찾을 수 없습니다. 내가 본 다른 옵션 중 일부는 텍스트 파일을 저장하는 것이 었으며이 경로로 가고 싶지 않습니다. 그러나 그것이 나보다 유일한 방법이라면.
내 코드는 다음과 같습니다.
MainPage.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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="http://xamarin.com/schemas/2014/forms"
mc:Ignorable="d"
x:Class="Counter.MainPage">
<StackLayout BackgroundColor="White" Padding="60" VerticalOptions="Start">
<Label Text="Editor"
x:Name="CounterLabel"
FontSize="25"
FontFamily="ComicSans"
HorizontalOptions="Center"
/>
<Editor Placeholder="Enter text here" AutoSize="TextChanges"/>
<Button Text="Telepromt" Clicked="NavigateButton_OnClicked">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="Scale"
Value="1" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="Scale"
Value="0.99" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
</StackLayout>
</ContentPage>
MainPage.xaml.cs
using GalaSoft.MvvmLight.Views;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Counter
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage() => InitializeComponent();
public class RoutedEventArgs: EventArgs
{
}
private async void NavigateButton_OnClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
}
}
Page1.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Counter.Page1">
<ContentPage.Content>
<StackLayout BackgroundColor="White" Padding="60" VerticalOptions="Center">
<Button Text="Main Page" Clicked="NavigateButton_OnClicked">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="Scale"
Value="1" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="Scale"
Value="0.99" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
당신 만의 텍스트를 전달하려는 경우 Editor
에 MainPage
받는 Page1
작업을 수행 할 수 있습니다 :
Editor
에서 이름 지정<Editor x:Name = "editor" Placeholder="Enter text here" AutoSize="TextChanges"/>
Editor
받는 사람의 텍스트를 Page1
생성자private async void NavigateButton_OnClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Page1(editor.Text));
}
Page1
생성자는 입력으로 받기public partial class Page1 : ContentPage
{
String MainPageEditorText;
public Page1(string editorText)
{
InitializeComponent();
MainPageEditorText = editorText; // Now you can access MainPageEditorText from anywhere in Page1 class!
...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다