Reputation: 249
I am trying to create (my first) custom control. It contains a few DependencyProperties that are not in the code provided here for the sake of simplicity.
public class StatusBlock : Label
{
static StatusBlock()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(StatusBlock),
new FrameworkPropertyMetadata(typeof(StatusBlock)));
}
}
Now I want to apply a custom layout and have created the following lines in Themes/Generic.xaml
. Obviously the layout is just for testing.
<Style TargetType="{x:Type Controls:StatusBlock}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:StatusBlock}">
<Grid Background="Red" MinHeight="100" MinWidth="100" >
<TextBlock Text="foobar"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
However, it is not applied. It compiles fine, but the style is not applied. Any ideas?
Upvotes: 3
Views: 1920
Reputation: 2168
When the style itself works (as you mentioned in the comment), the issue is in the relationship of your dll and your project where you want to display the control. Add this to you AssemblyInfo.cs
of the dll project (it needs using System.Windows;
):
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Upvotes: 4