Applied style in WPF ignores properties.

Posted by Quenton Jones on Stack Overflow See other posts from Stack Overflow or by Quenton Jones
Published on 2010-06-02T18:03:13Z Indexed on 2010/06/02 18:04 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

Here's the conundrum. In two different places in my application, I use a border with the exact same appearance. In an never-ending fight against code bloat and unmanageable code, I want to define the border's appearance in a style to use when I create the border. Strangely, several of the properties I set are being ignored.

Here's the code I use to create the style. Simple enough.

Style borderStyle = new Style(typeof(Border));

borderStyle.Setters.Add(new Setter(Border.BorderBrushProperty, Brushes.Black));
borderStyle.Setters.Add(new Setter(Border.BorderThicknessProperty, new Thickness(4)));
borderStyle.Setters.Add(new Setter(Border.OpacityProperty, 1.0));

return borderStyle;

But when I set the style, the opacity property is left at its original value of 0.7. I have also tried setting the background of the border to a brush I created. It too is ignored.

Thanks for any insights you may have.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about styles