1

I have created a user control that needs to reference an external resource dictionary file. A style within this resource file is then used against a textbox in the user control.

The external resource dictionary file is as follows:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="ValidatedTextboxStyle" TargetType="{x:Type TextBox}"> ... </Style> 

I then import this into the user control as follows: (with the long file location removed)

<Control.Resources> <ResourceDictionary x:Key="Test" Source="..." /> <common:StringCollapseVisibilityConverter x:Key="StringCollapseVisibilityConverter" /> </Control.Resources> 

The WPF designer forces me to give it a "key" due to the other resource that is referenced.

Without the dictionary having a name, you would normally reference it like:

Style="{StaticResource ValidatedTextboxStyle}" 

How would I reference the style that has name "ValidatedTextboxStyle" within the external resource file taking into account that the imported resource dictionary is given the key name "Test"?

1 Answer 1

1

Merged the dictionary in your control and you can use it like earlier via StaticResource.

<Control.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="..." /> </ResourceDictionary.MergedDictionaries> <common:StringCollapseVisibilityConverter x:Key="StringCollapseVisibilityConverter" /> </ResourceDictionary> </Control.Resources> 

Also, you can omit setting x:Key now on resource dictionary since all the defined resources in resource dictionary are merged into your control resources.

Now, you can use like earlier:

Style="{StaticResource ValidatedTextboxStyle}" 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply. But it doesn't like this as the converter is not of type resource dictionary
Oh yeah right. You have to move it out of mergerdDictionaries tag. Updated the answer.
Can this be done once globally? If yes, in which file? app.xaml?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.