FrameworkElement.BaseUri 屬性

定義

取得統一資源識別項 (URI) ,表示 XAML 載入時 XAML 建構物件的基底 URI。 這個屬性適用于執行時間的 URI 解析。

public:
 property Uri ^ BaseUri { Uri ^ get(); };
Uri BaseUri();
public System.Uri BaseUri { get; }
var uri = frameworkElement.baseUri;
Public ReadOnly Property BaseUri As Uri

屬性值

XAML 載入時物件的基底統一資源識別項 (URI) 。

範例

此範例會在將映射來源重設為備份/預設值的事件處理常式中使用 BaseUri。 BaseUri 用於新統一資源識別項的「路徑」部分, (URI) 用於 BitmapImage 建 構函式呼叫,其餘 URI 會指向應用程式在其資源中擁有的影像檔。 若要在 UWP 應用程式的內容中查看此程式碼,請參閱 CameraCaptureUI 範例

void SDKSample::Page::Reset_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    rootPage->NotifyUser("The photo will be shown here.", NotifyType::StatusMessage); 
    ResetButton->Visibility = Windows::UI::Xaml::Visibility::Collapsed; 
    CapturedPhoto->Source = ref new BitmapImage(ref new Windows::Foundation::Uri(BaseUri->AbsoluteUri, "Assets/placeholder-sdk.png")); 
     // Remove file from Application Data 
    appSettings->Remove("capturedPhoto"); 
}
private void Reset_Click(object sender, RoutedEventArgs e)
{
    ResetButton.Visibility = Visibility.Collapsed;
    CapturedPhoto.Source = new BitmapImage(new Uri(this.BaseUri, "Assets/placeholder-sdk.png"));

    // Clear file path in Application Data 
    appSettings.Remove(photoKey);
}

備註

XAML 剖析器可以根據頁面中物件的內容來評估資源的參考,因此可以評估在統一資源識別元 (URI) 屬性中顯示為部分路徑的內容。 針對執行時間程式碼,統一資源識別項 (URI 的定義規則) 類型不允許部分路徑。 在執行時間,您可以從剖析 XAML 頁面所建立的物件範圍使用 BaseUri,以取得 URI 的「路徑」部分,然後使用特定資源參考來完成 URI。

適用於