We have answer of your question!

100% solved queries, no empty question

Question: Use style from external assembly, which is in another solution


0

I have a solution:
Image
In this solution I have a style which I want to use in another project, the style is in resource dictionary format. Note: This solution contains WPF class library.

In another solution I have a project, the solution explorer looks like this:
Image

Now, I want to reference the CustomWindow.xaml resource dictionary in my App.xaml, so I could use it in my MainWindow.xaml.

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="???"/>
    <ResourceDictionary.MergedDictionaries>
<ResourceDictionary>

How to do so?

The solution was:

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/CustomWindow;component/Styles/CustomWindow.xaml"/>
    <ResourceDictionary.MergedDictionaries>
<ResourceDictionary>

Now, whenever I add the Style to my window from that DLL like this:

Style="{DynamicResource CustomWindowStyle}"

It shows wiggly lines on the code, and whenever I put a cursor on it, it shows an error: "Object reference not set to an instance of an object"
Note: It compiles, but the designer won't shot how it really looks like.

Question author Nerijus-pocevi%c4%8dius | Source

Answer


1


Use pack URI: https://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx. In your case, it should be something like

<ResourceDictionary>
   <ResourceDictionary.MergedDictionaries>
       <ResourceDictionary Source="pack://application:,,,/<assembly name>;component/Styles/CustomWindow.xaml"/>
   <ResourceDictionary.MergedDictionaries>

If you are going to share resources, you might want to move the resources to another assembly.

Answer author Ivan-vargas

Tickanswer.com is providing the only single recommended solution of the question Use style from external assembly, which is in another solution under the categories i.e c# , wpf , . Our team of experts filter the best solution for you.

Related Search Queries:

wpf resourcedictionary from another assembly ,


You may also add your answer

Thanks for contributing an answer to Tick Answer!