2

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???

1 Answer 1

1

OK I have found a solution myself. I should implement IUriContext interface, which has only one property: Uri BaseUri, this is exactly what I want.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.