1

Related to an earlier question I asked, I've seen that there's both LoadComponent() and XamlReader.Load(). They're similar enough that I'm not quite sure which one I should use in what case.

So, in essence, what's the difference between the two?

Thanks!

Community
  • 1
  • 1
djcouchycouch
  • 12,724
  • 13
  • 69
  • 108

2 Answers2

4

MSDN:

Speculation
I would guess that LoadComponent calls XamlReader.Load(). LoadComponent looks more like an application level service and is probably used by the application itself to load all of the xaml resources. XamlReader is the specific library call for what you want.

Think about it as LoadComponent is an Application Service where XamlReader is the library containing the functionality.

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57
Alan Jackson
  • 6,361
  • 2
  • 31
  • 32
1

Application.LoadComponent:Application will first preload resources as a 'Package' and register it in PreloadedPackage class, when calling LoadComponent method, wpf first check if package exsits and resource exists, then check if resouse is xaml or baml, finally load the resource stream with provided BaseUri

If resource is baml, LoadComponent will use Baml2006Reader, otherwise use XamlReader to process resource stream.

XamlReader.Load can load xaml resources outside the assembly.

dexiang
  • 1,345
  • 16
  • 23