I have an custom control, which has an Image element with its Source property exposed to user, like this
<ControlTemplate>
<Image x:Name="PART_Image" Source="{Binding ImageUri, RelativeSource={RelativeSource TemplatedParent}}"/>
</ControlTemplate>
where ImageUri is an property in the control class, like this
public Uri ImageUri { get; set; }
this custom control is in an assembly customcontrol.dll , I can reference and use this control in an exe with no problem, like this
<cc:MyControl ImageUri="/Resources/Image.png" />
where Image.png is a resource of the exe project.
but if I reference and use this control in an dll assembly, there is a problem, I have to use a absolute "pack://..." uri to reference an image in the calling dll, if I use an relative uri like "Resources/Image.png", the resource cant be loaded, it turns out, when this uri is applied on the Image element, it resolves the relative uri from customcontrol.dll, not the calling dll assembly, so I want to do this:
public Uri ImageUri {
get { ...... }
set {
if (!value.IsAbsolute) {
// Get the assembly name of parent xaml file or code
// and construct a "pack://" uri from the assembly name
// and value.OriginalString, but how ??????
}
}
}
How can I get the assembly of the xaml code that uses my custom control ? if the control is used in code maybe I can use GetCallingAssembly in my methods, but xaml stuff is called from PresontationCore.dll, how can I find out the xaml assembly ???