簡體   English   中英

如何使用Xamarin和SQL Server從數據庫下載pdf

[英]How to download pdf from database using Xamarin and SQL Server

我有Xamarin形式的列表視圖,您可以在以下屏幕截圖中看到它:

在此處輸入圖片說明

這是我的數據庫結構:

在此處輸入圖片說明

在我的列表視圖中,我有帶按鈕的數據; 當用戶單擊下載按鈕時,應根據ID從數據庫下載PDF文件。

這是我的XAML代碼

<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <StackLayout Orientation="Vertical" Padding="12,6">
                <Label Text="{Binding Name}" 
                       FontSize="24" 
                       Style="{DynamicResource ListItemTextStyle}" />
                <Label Text="{Binding Department}"  
                       FontSize="18" 
                       Opacity="0.6"
                       Style="{DynamicResource ListItemDetailTextStyle}"/>
                <Button Text="Download"/>
            </StackLayout>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>
<Button Text="Download" Clicked="ShowPDF" CommandParameter="{Binding path}"> </Button>

protected void ShowPDF(object sender, EventArgs args) {

  Button button = (Button)sender;

  string path = button.CommandParameter;

  string url = "http://myserver.tld" + path;

  Navigation.PushAsync(new PDFView(url));
}

您將需要創建一個包含WebView的PDFView頁面,將該URL傳遞給WebView以顯示PDF。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM