ResourceDictionary Source="~/test.xaml"

In september ctp I can set "Source" to execution directory based path to loose xaml,is something changed in november ctp It wan't work anymore.And if it really changed,why

Thanks.


Answer this question

ResourceDictionary Source="~/test.xaml"

  • Merianos Nikos

    Nice findBig Smile,if you try 
    PackUriHelper.Create(new Uri("file://h:/./test.xaml"))

    System.ArgumentException: The URI should not be absolute (absolute URI consists
    of scheme name, authority).
       at System.IO.Packaging.PackUriHelper.ThrowIfAbsoluteUri(Uri uri)
       at System.IO.Packaging.PackUriHelper.CreatePartUri(Uri partUri)
       at a.Main(String[] args)

    but if you try

    PackUriHelper.Create(new Uri("file://h:/./test.xaml").MakeRelativeUri(u))

    System.ArgumentException: The URI should be absolute.
       at System.IO.Packaging.PackUriHelper.ValidatePackageUri(Uri packageUri)
       at System.IO.Packaging.PackUriHelper.Create(Uri packageUri, Uri partUri, Stri
    ng fragment)
       at System.IO.Packaging.PackUriHelper.Create(Uri packageUri)
       at a.Main(String[] args)

    SO,how I can get perfectly valid URI


  • tjeremenko

    Ok,I've got something that LOOKS like properly formatted pack uri from PackUriHelper:

    pack://file:,,,H:,test_project/test.xaml
    for h:\test_project\test.xaml

    but that's not work ever:

    System.Windows.Serialization.BamlParseException was unhandled
      Message="Error at element 'ResourceDictionary' in markup file 'myapp.xaml' : Cannot assign value 'pack://file:,,,H:,test_project/test.xaml' to property 'System.Windows.ResourceDictionary.Source'.."
      Source="PresentationFramework"
      LineNumber=0
      LinePosition=0

    Something is terribly wrong...


  • Nothern

    OK,I got it-you can set Source to "test.xaml" or "/test.xaml" but you MUST include "test.xaml" in project with build action "Content" and "Copy to output directory",as noted in this forum before.I don't understand that requirement because file simply placed in the same dir as output .exe-no dll,no embedding-some kind of magic going onSmile

    Maybe,someone find this info useful.

  • PainJunkie

    Hi,

    Seems like you are mixing two incompatible things (absolute path/ local file and siteoforigin)
    This protocol abstracts where the data comes from.

    If you want to get the data from a local path, use the standard file protocol.
    "file:///h:/Your%20Folder/subFolder/yourPath/yourFile.xaml"
    ( Note that this won't work for web application since you will need local to the machine - or you will need to change the security permissions ).


    If you want to access a file from the SiteOfOrigin's subdirectory, use the following syntax:
    "pack://siteoforigin,,,/yourPath/yourFile.xaml"

    If your application lives (or "was deployed from" in case of a web application) on "h:\your folder\subfolder", the above will get resolved internally as "h:\your folder\subfolder\youtPath\yourFile.xaml"





  • Jagger_Mack

    file:///h:/Your%20Folder/subFolder/yourPath/yourFile.xaml this dosen't work for simple windows app,try it youself:

    Error at element 'ResourceDictionary' in markup file 'myapp.xaml' : Cannot assign value 'file:///h:/Your%20Folder/subFolder/yourPath/yourFile.xaml' to property 'System.Windows.ResourceDictionary.Source'..

    Thanks anyway.

  • CompactDev

    Thank you,for information but how about run from local disk directory-what should I set if resource .xaml located in the same dir too
    Sorry,but I can't find description of pack:// uri schemeSad


  • Ad the Lad

    I believe the support is still there, but you're using the deprecated path format. Specifically the tilde approach (~/) is no longer supported.

    You now need to use the "pack" protocol like so:

    pack://siteoforigin:,,,/test.xaml

    HTH,
    Drew

  • ResourceDictionary Source="~/test.xaml"