locked
Exporting resource dictionaries from a library RRS feed

  • Question

  • I followed the discussion

    https://social.msdn.microsoft.com/Forums/en-US/b8c27ea2-f7f7-4a96-9f71-61f973ebd033/resource-dictionaries-in-winrt-class-libraries-dlls

    about using resource libraries embedded in a library, but it doesn;t seem to work.

    No matters whether "Generate library layout" (now you can set it in Visual Studio by ticking "Generate Library Layout" checkbox in Properties/Build for the library) is enabled or disabled, the output doesn't go to main project, but to the library folders. As a result, I get message "An error occured by finding a resource library" while trying to include xaml into MergedDictionaries for App.xaml of the main project, and though the compilation succeeds, the application crashes straight after splash screen.


    Sunday, October 4, 2015 11:05 PM

Answers

  • Hello pcyanide,

    Welcome to the MSDN forum and I would suggest you could check this guide post to add a proper tag for the thread title to let us understand your problem clearer.

    >>the output doesn't go to main project, but to the library folders.

    Yes, from my side, it is the same. However, I checked you provided link, and people on that thread does not mention it should be ported to the primary project folder. What I think after the “Generate library layout” is checked, it would generate a right layout and put all the resources next to the dll in a folder named with the same name as class library.

    It is not clear how you process the directory in a dll, here I created a sample with the detail steps which could work on my side, you could follow it to see if it works for you:

    1.Create a blank UWP app and add below XAML to the main page:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    
            <StackPanel VerticalAlignment="Center">
    
                <Button/>
    
            </StackPanel>
    
        </Grid>
    

    2.Create a class library and add a directory file, add these content to it:

    <Style TargetType="Button">
    
            <Setter Property="Height" Value="100"/>
    
            <Setter Property="Width" Value="300"/>
    
            <Setter Property="BorderThickness" Value="5" />
    
            <Setter Property="Foreground" Value="Blue" />
    
            <Setter Property="BorderBrush" >
    
                <Setter.Value>
    
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    
                        <GradientStop Color="Yellow" Offset="0.0" />
    
                        <GradientStop Color="Red" Offset="0.25" />
    
                        <GradientStop Color="Blue" Offset="0.75" />
    
                        <GradientStop Color="LimeGreen" Offset="1.0" />
    
                    </LinearGradientBrush>
    
                </Setter.Value>
    
            </Setter>
    
        </Style>
    

    3.Build the class library and add a reference to it from the UWP project.

    4.In the app.xaml page, add below code:

    <Application.Resources>
    
            <ResourceDictionary >
    
                <ResourceDictionary.MergedDictionaries>
    
                    <ResourceDictionary Source="ms-appx:///ClassLibrary1/Dictionary3.xaml"/>
    
                </ResourceDictionary.MergedDictionaries>
    
            </ResourceDictionary>
    
        </Application.Resources>
    

    5.Run the project and on my side, it shows me a button with a specific style as:

    Please have a try with my steps, if this does not work for you, please feel free to let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Fred Bao Tuesday, October 6, 2015 4:49 AM
    • Proposed as answer by Fred Bao Monday, October 19, 2015 11:59 AM
    • Marked as answer by Fred Bao Tuesday, October 20, 2015 4:17 AM
    Tuesday, October 6, 2015 4:48 AM