Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Setting BitmapImage.UriSource in a XAML file read with XamlReader [VB][WPF]

Setting BitmapImage.UriSource in a XAML file read with XamlReader [VB][WPF]

Scheduled Pinned Locked Moved WPF
wpfcsharphtmlcssdotnet
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayme65
    wrote on last edited by
    #1

    Hello, My WPF application (WpfApplication1) is, for its XAML part, composed of an single empty grid. Elements are loaded inside this grid from an external XAML file, read through XamlReader. This external Xaml file contains (for the purpose of this example) a URL to an image which should be located in the 'My documents' user folder. The problem is that during importation the url from images should be relative to the application which is loading the file! In other words, this URL should be relative to the application (pack://siteoforigin:, pack://application) ...and in my case, this path is 'outside' from that context and should be built this way: Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments) & "Theme\" So, I wrote a Converter, hoping to build the complete path url...but without succes!! > 'Impossible to create the unknow type '{clr-namespace:WpfApplication1}imgurlConvert'.' The application XAML part:

    The application VB part:

    Imports System.IO
    Class MainWindow
    Public Shared ThemeTempFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Theme\"
    Public Shared themeGrid As Grid
    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    Debug.Print(ThemeTempFolder)
    loadInterface()
    End Sub
    Sub loadInterface()
    ' Load extracted (grid) xaml file as content of the window
    Dim GridUri As String = ThemeTempFolder & "theme.xaml"
    Dim fs As FileStream = New FileStream(GridUri, FileMode.Open, FileAccess.Read)
    Dim sri = TryCast(System.Windows.Markup.XamlReader.Load(fs), Grid)
    Me.Content = sri
    fs.Close()
    ' Liens, dans le code, aux ?l?ments de l'interface charg?e en Xaml.
    themeGrid = LogicalTreeHelper.FindLogicalNode(sri, "themeGrid")
    End Sub
    End Class
    Public Class imgurlConvert
    Implements IValueConverter
    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
    Di

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups