古詩詞大全網 - 個性簽名 - 如何查閱 windows 用戶 uri

如何查閱 windows 用戶 uri

Windows 運行時方法只接受絕對 URI。 如果將壹個相對 URI 傳遞給 Windows 運行時 方法,則將會引發ArgumentException 異常。 原因如下:在 .NET Framework 代碼中使用 Windows 運行時 時,Windows.Foundation.Uri類顯示為 Intellisense 中的 Uri。 Uri 類允許相對 URI,但 Windows.Foundation.Uri 類不允許。 這也適用於 Windows 運行時 組件中公開的方法。 如果組件公開接收 URI 的方法,則代碼中的簽名包含 Uri。 但是,對於組件的用戶,簽名包含Windows.Foundation.Uri。 傳遞給組件的 URI 必須是絕對 URI。

本主題演示了如何檢測絕對 URI 以及如何在引用應用包中的資源時創建壹個。

檢測和使用絕對 URI

使用 Uri.IsAbsoluteUri 屬性確保在將 URI 傳遞給 Windows 運行時 之前,該 URI 是絕對的。 使用此屬性比捕獲和處理ArgumentException 異常更為有效。

將絕對 URI 用於應用包中的資源

如果想要為應用包包含的資源指定 URI,可以使用 ms-appx 或 ms-appx-web 方案來創建絕對 URI。

下面的示例演示如何同時使用 XAML 和代碼,將 WebView 控件的 Source 屬性以及 Image 控件的 Source 屬性設置為包含名為 Pages 文件夾中的資源。

C#

VB

private void Button_Click_1(object sender, RoutedEventArgs e)

{

webview1.Source = new Uri("ms-appx-web:///Pages/HTMLPage2.html", UriKind.Absolute);

}

XAML

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

<WebView Name="webview1" HorizontalAlignment="Center" Height="222"

VerticalAlignment="Top" Width="310" Margin="472,57,553,0"

Source="ms-appx-web:///Pages/HTMLPage1.html"/>

<Button Content="Button" HorizontalAlignment="Left" Margin="322,185,0,0"

VerticalAlignment="Top" Click="Button_Click_1"/>

<Image HorizontalAlignment="Left" Height="100" Margin="208,123,0,0" VerticalAlignment="Top"

Width="100" Source="ms-appx:///Pages/weather.jpg" />

</Grid>