我正在制作一個應用程式,您可以在其中點擊按鈕并打開某個網頁。我對應用程式開發很陌生。頁面上會有多個帶有不同鏈接的按鈕(從鏈接資料庫中獲取)。因此,如果可能的話,必須有某種方法來制作接受來自 xaml 頁面的鏈接的通用方法。打開這樣的鏈接的最佳方式是什么?任何幫助是極大的贊賞
這是小表單的當前 xaml 代碼
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Vertical">
<Label Text="Link 1" TextColor="{StaticResource Text}" FontSize="18" FontAttributes="Bold" x:Name="label"/>
<StackLayout Orientation="Horizontal">
<Label Text=" 85" TextColor="{StaticResource Text}" FontSize="18"/>
<Label Text=" /-12" TextColor="{StaticResource Text}" FontSize="18"/>
</StackLayout>
</StackLayout>
<Button Margin="0,10,0,0" Text="Open Link" BackgroundColor="{StaticResource Primary}" TextColor="{StaticResource Accent}" FontSize="13" Clicked="OpenBrowser"/>
</StackLayout>
這是 xaml.cs 中的當前 OpenBrowser 代碼
public async Task OpenBrowserAsync()
{
await Browser.OpenAsync("https://www.google.com");
}
private void OpenBrowser(object sender, EventArgs e)
{
_ = OpenBrowserAsync();
}
uj5u.com熱心網友回復:
您可以在ClassId屬性中嵌入網址
<Button Text="Open Link" Clicked="OpenBrowser" ClassId="http://www.google.com" ... />
然后在你的處理程式中
private async void OpenBrowser(object sender, EventArgs e)
{
var button = (Button)sender;
var url = button.ClassId;
await Browser.OpenAsync(url);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/323720.html
標籤:C# xml xamarin.forms
上一篇:將GridViewColumn系結到List<EntityFrameworkCore'sEntity>中的空屬性
