Я очень плохо знаком с Xamarin , и я искал способ сохранить текст из редактора на главной странице, а затем отобразить его на второй странице. Я знаю, что это не может быть так сложно, но я не могу найти решение. Некоторые из других вариантов, которые я видел, были для сохранения текстового файла, и я действительно не хочу go этот маршрут. Однако, если это единственный способ, чем я буду.
Вот мой код:
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>