我正在創建一個顯示條目和按鈕的簡單 xaml 頁面,我想為按鈕創建一個事件以將條目值顯示到另一個頁面中。我應該使用 MVVM 還是有另一種方法可以做到這一點。
這是第一頁:
<!-- 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>
按鈕中的“掃描”方法:
private void Scan(object sender, EventArgs e)
{Application.Current.MainPage = new NavigationPage(new Scanner());}
掃描儀頁面:
<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>
uj5u.com熱心網友回復:
只需通過頁面建構式傳遞一個值
var value = MyEntryControl.Text;
Application.Current.MainPage = new NavigationPage(new Scanner(value))
并且在Scanner
public Scanner(string value)
{
InitializeComponent();
MyLabelControl.Text = value;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/481174.html
