Jaa


FrameworkElement.BaseUri Property

Definition

Gets a Uniform Resource Identifier (URI) that represents the base Uniform Resource Identifier (URI) for an XAML-constructed object at XAML load time. This property is useful for Uniform Resource Identifier (URI) resolution at run time.

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

Property Value

The base Uniform Resource Identifier (URI) for an object at XAML load time.

Examples

This example uses BaseUri in an event handler that resets an image source to a backup/default. BaseUri is used for the "path" part of a new Uniform Resource Identifier (URI) that is used for a BitmapImage constructor call, the rest of the Uniform Resource Identifier (URI) points to an image file that the app has in its resources. To see this code in context, see the CameraCaptureUI sample.

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

Remarks

The XAML parser can evaluate references to resources based on the context of the object in a page, and can thus evaluate what appear to be partial paths in a Uniform Resource Identifier (URI) property. For run-time code, the definition rules for the Uniform Resource Identifier (URI) types don't permit partial paths. At run time, you can use BaseUri from the scope of an object that was created by parsing a XAML page in order to get the "path" part of a Uniform Resource Identifier (URI), and then complete the Uniform Resource Identifier (URI) with a particular resource reference.

Notes for previous versions

Windows 8 In Windows 8, the URI returned by BaseUri from style or template parts could return values that represented a project default rather than a value that was specific for the XAML file that created an object. The BaseUri behavior has been corrected starting with Windows 8.1. But if you relied on the previous behavior of BaseUri and changed your XAML compositions or resource lookups because of it, you might want to examine the areas of your code that make BaseUri calls. Verify that the combined Uniform Resource Identifier (URI) you use for finding resources or localization info work as expected when your app is recompiled for Windows 8.1. Apps that were compiled for Windows 8 but running on Windows 8.1 continue to use the Windows 8 behavior.

Applies to