I have this simplified structure:

Project 1 (UI library)

  • Styles folder
    • CustomControlStyle.xaml (that is ResourceDictionary conaining styles and templates)
<ResourceDictionary links to ms ramoved cuz spam filter
                    xmlns:local="clr-namespace:MyCode.UI.Styles"
                    xmlns:controls="clr-namespace:MyCode.UI.Controls">
    <Style TargetType="{x:Type controls:CustomControl}"
           x:Key="CustomControlStyle">
       <Setter Property="Template">
           <Setter.Value>
               <ControlTemplate TargetType="{x:Type controls:CustomControl}">
                   <Grid>
                       <Border x:Name="PART_ControlContainer"
                               Visibility="{Binding Path=HasContent, Converter={StaticResource BTVC}, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                   </Grid>
               </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
    • Styles.xaml (another ResourceDictionary where all my theme styles merged into MergedDictionary property.
<ResourceDictionary x:Class="MyCode.UI.Styles.StylesResourceDictionary"
                    links to ms ramoved cuz spam filter
                    xmlns:ctl="clr-namespace:MyCode.UI.Controls"
                    xmlns:local="clr-namespace:MyCode.UI.Styles"
                    xmlns:s="clr-namespace:System;assembly=mscorlib">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Converters.xaml" />
        <ResourceDictionary Source="CustomControlStyle.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type ctl:CustomControl}" BasedOn="{StaticResource CustomControlStyle}"/>
</ResourceDictionary>
    • Converters.xaml
<ResourceDictionary x:Class="MyCode.UI.Styles.Converters"
                    links to ms ramoved cuz spam filter
                    xmlns:cnv="clr-namespace:MyCode.UI.Converters">
    <cnv:BooleanToVisibilityConverter x:Key="BTVC" />
</ResourceDictionary>

Project 2 (Wpf app) referencing Project 1

  • App.xaml
<Application x:Class="MyCode.UI.Demo.App"
             links to ms ramoved cuz spam filter
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             links to ms ramoved cuz spam filter
             mc:Ignorable="d"
             xmlns:local="clr-namespace:MyCode.UI.Demo">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MyCode.UI;component/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

It compiles, but on start throws Exception: Cannot find resource named 'BTVC' System.Windows.Markup.XamlParseException.

It works if I add Converters.xaml into CustomControlStyle.xaml‘s Merged dictionaries.

I read MSDN articles about resource lookup and yet cannot understand why resource cannot be found.

Resource tree should look something like:

Application
 ResourceDictionary
  MergedDictionaries
   ResourceDictionary (Styles.xaml)
    MergedDictionaries
     ResourceDictionary (Converters.xaml)
      BooleanToVisibilityConverter (BTVC)
     ResourceDictionary (CustomControlStyle.xaml)
      Style
       Template
        ControlTemplate
         Grid
          Border
           Visibility (Binding, referencing BTVC)

Control, that uses style placed alone to MainWindow.xaml

<Window x:Class="MyCode.UI.Demo.App.MainWindow"
        links to ms ramoved cuz spam filter
        xmlns:controls="clr-namespace:MyCode.UI.Controls;assembly=MyCode.UI"
        xmlns:local="clr-namespace:MyCode.UI.Demo.App"
        mc:Ignorable="d">
    <CustomControl />
</Window>