I have a custom user control that contains a combo box. I\'ve added a ComboBoxWidth dependency property to allow developer to set width if they want. Using a style setter, I\'
A so-called "local value" of a dependency property, like
this.ComboBoxWidth = 175.0;
has higher value precedence than a value from a Style Setter, like
<Setter Property="ComboBoxWidth" Value="400"/>
Hence the Style Setter has no effect.
You should assign a new default value by overriding dependency property metadata:
public class AngleUserControl : ...
{
static AngleUserControl()
{
ComboBoxWidthProperty.OverrideMetadata(
typeof(AngleUserControl),
new PropertyMetadata(175d));
}
}
See Dependency Property Value Precedence for reference.