I'm creating a simple xaml page who display an entry and a button, I want to create an event for the button to display the entry value into another page. Should I use the MVVM or there's another method to do that.
this is the first page:
<!-- Entry to get machine name -->
<border:SfBorder
BackgroundColor="{DynamicResource Gray-Bg}"
BorderColor="{Binding Source={x:Reference PasswordEntry}, Path=IsFocused, Converter={StaticResource ColorConverter}, ConverterParameter=3}"
Style="{StaticResource LoginFormBorderlessEntryBorderStyle}">
<Grid ColumnDefinitions="*, Auto">
<control:BorderlessEntry
Margin="15,0"
HeightRequest="40"
Placeholder="Le nom de la machine"
Style="{StaticResource BorderlessEntryStyle}"/>
</control:BorderlessEntry>
</Grid>
</border:SfBorder>
</StackLayout>
<!-- Scanner button -->
<buttons:SfButton
Grid.Row="5"
Margin="0,16"
HorizontalOptions="Fill"
Style="{StaticResource GradientButtonStyle}"
Text="Scanner le code QR"
Clicked="Scan"
/>
</Grid>
</StackLayout>
the "scan" method in the button:
private void Scan(object sender, EventArgs e)
{Application.Current.MainPage = new NavigationPage(new Scanner());}
the scanner page:
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label ............ the entry value...... />
<Label x:Name="scanResultText" FontSize="Large"/>
<zxing:ZXingScannerView IsScanning="True" OnScanResult="ZXingScannerView_OnScanResult"/>
</StackLayout>
CodePudding user response:
just pass a value via the page constructor
var value = MyEntryControl.Text;
Application.Current.MainPage = new NavigationPage(new Scanner(value))
and in the Scanner
public Scanner(string value)
{
InitializeComponent();
MyLabelControl.Text = value;
}