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 (URI) 的「路徑」部分,用於 BitmapImage 建 構函式呼叫、其餘統一資源識別項 (URI) 指向應用程式在其資源中擁有的影像檔。 若要查看內容中的此程式碼,請參閱 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);
}
Private Sub Reset_Click(sender As Object, e As RoutedEventArgs)
    ResetButton.Visibility = Visibility.Collapsed
    CapturedPhoto.Source = New BitmapImage(New Uri(Me.BaseUri, "Assets/placeholder-sdk.png"))
    ' Clear file path in Application Data 
    appSettings.Remove(photoKey)
End Sub

備註

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

舊版的注意事項

Windows 8 在 Windows 8中,BaseUri 從樣式或範本元件傳回的URI可能會傳回代表專案預設值的值,而不是建立物件之 XAML 檔案特有的值。 從 Windows 8.1 開始,已更正 BaseUri 行為。 但是,如果您依賴 BaseUri 的先前行為,並變更您的 XAML 組合或資源查閱,您可能會想要檢查進行 BaseUri 呼叫的程式碼區域。 確認合併的統一資源識別項 (URI) 當您的應用程式重新編譯Windows 8.1時,用於尋找資源或當地語系化資訊的運作方式如預期般運作。 針對 Windows 8 編譯但在 Windows 8.1 上執行的應用程式會繼續使用 Windows 8 的行為。

適用於