Create ControlTemplate programmatically in wpf

Posted by Thomas Stock on Stack Overflow See other posts from Stack Overflow or by Thomas Stock
Published on 2010-03-28T15:58:32Z Indexed on 2010/03/28 16:03 UTC
Read the original article Hit count: 1266

Filed under:
|
|

Hi, How can I programmatically set a button's template?

Polygon buttonPolygon = new Polygon();
buttonPolygon.Points = buttonPointCollection;
buttonPolygon.Stroke = Brushes.Yellow;
buttonPolygon.StrokeThickness = 2;

// create ControlTemplate based on polygon
ControlTemplate template = new ControlTemplate();
template.Childeren.Add(buttonPolygon); // This does not work! What's the right way?

//create button based on controltemplate
Button button = new Button();
button.Template = template;

So I need a way to set my Polygon as the button's template.. Suggestions?

Thanks.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about controltemplate