I have the following Problem: I create a custom control which inherits from an already existing one, i.e.
public class CustomButton : Button
{
public Boolean AdditionalProperty { get; set; }
}
This works without problem, but if I try to Style the element it doesn’t apply the style
<style TargetType="local:CustomButton">
<!-- Setters -->
</style>
What am I doing wrong? I add the CustomButton programmatically, is this the problem? I tried the following as well:
CustomButton customButton = new CustomButton();
customButton.Style = FindResource("<key>");
someGrid.Children.Add(customButton);
Try
TargetType="{x:Type local:CustomButton}"Edit:
Source: MSDN