WPF user control pattern not applicable

I am sure that this question or its derivatives have been asked several times, but I could not find anything that would help me solve the problem, so I ask. Please feel free to direct me to a duplicate that I am sure exists, but I cannot find. Apparently I'm not so good with keywords.

I have a user control, it has its own resource dictionary, used only to define a control template. This dictionary is then merged into Generic.xaml.

The problem is that when this control is displayed in the user interface, it has nothing inside it. I used Snoop to find out. The control is in the user interface, but it is completely empty.

Below you will find elements that I think are responsible for the problem. Any help or advice you can offer is greatly appreciated.

The relevant parts of my folder structure are as follows:

My directory structure

BasicTemplate.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WPFSpecBuilder.Layouts.Templates">

    <Style TargetType="{x:Type local:BasicTemplate}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BasicTemplate}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <TextBlock Text="This is a basic template." />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Layouts/Templates/XAML/BasicTemplate.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
+5
source share
3 answers

Try the following:

  • Set the assembly action to BasicTemplate.xaml on the page.

  • BasicTemplate.xaml Generic.xaml:

    ResourceDictionary Source = "/WPDSpecBuilder; ///Xaml/BasicTemplate.xaml"

.

+1

, , . / :

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Layouts/Templates/XAML/BasicTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
+1

Try:

<ResourceDictionary.MergedDictionaries>
     <ResourceDictionary Source="pack://application:,,,/WPDSpecBuilder;component/Layouts/Templates/XAML/BasicTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>

For more details see here Pack Uri

+1
source

All Articles