Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:04:53+00:00 2026-06-08T08:04:53+00:00

I need to create this style using c# code to generate dynamic points for

  • 0

I need to create this style using c# code to generate dynamic points for polygon instead of static ones in xaml tags.

 <Style  x:Key="Mystyle" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid  >

                            <Polygon  Points="0,0 0,100 50,200" Fill="{TemplateBinding Background}"
                         Stroke="{TemplateBinding BorderBrush}" DataContext="{Binding}" />
                        <ContentPresenter HorizontalAlignment="Center"
                                      VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:04:55+00:00Added an answer on June 8, 2026 at 8:04 am
    public MainWindow()
        {
            //Control Template .. We cannot add children to the Control Template Directly
    
            ControlTemplate controlTemplate = new ControlTemplate(typeof(Button));
    
            //These points you can set Dynamically as your requirement
            PointCollection points= new PointCollection(new List<Point> { new Point() { X = 0, Y = 0 }, new Point() { X = 0, Y = 50 }, new Point() { X = 100, Y = 200 } });
            var polygon = new FrameworkElementFactory(typeof(Polygon));
    
            //You can also set Binding rather than static color for fill
            polygon.SetValue(Polygon.PointsProperty, points);
            polygon.SetValue(Polygon.FillProperty, new SolidColorBrush(Colors.Pink));
    
            //ContentPresenter
            var contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));
            contentPresenter.SetValue(ContentPresenter.ContentProperty,"this is content Presenter");
    
            //Grid
            var grid = new FrameworkElementFactory(typeof(Grid));
            grid.SetValue(Grid.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
            grid.AppendChild(polygon);
            grid.AppendChild(contentPresenter);
            controlTemplate.VisualTree = grid;
    
            //Style
            Style style = new Style(typeof(Button));
            style.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.Red)));
            style.Setters.Add(new Setter(TemplateProperty, controlTemplate));
            this.Resources.Add("SomeKey", style);
    
            //Initialize
            InitializeComponent();
        }
    
     <Grid>
        <Button Style="{DynamicResource SomeKey}"/>
    </Grid>
    

    I hope this will help you to give the idea how to do. And yes you can set all bindings in code behind like Fill of polygon and Content of ContentPresenter .

    Note It is Recommended to use Xaml for creating Templates . As in your problem all what you want is dynamic Points of Polygon . Its better You bind Points property of Polygon rather than creating entire Template in CodeBehind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this code where i create an xlsx file and i need
I need to create this url: www.example.com/directory/[state]-financial-planners Where [state] will be different depending on
I need to create this layout and I'd like to do as much of
I need to create lines like this: <li data-target=c1.html><span>I. </span><span>Het tijdperk der goden</span></li> I
Hi I need to create string like this: drawtext=fontfile=/Users/stpn/Documents/Video_Experiments/fonts/Trebuchet_MS.ttf:text='content':fontsize=100:fontcolor=red:y=h/2 I want to do something
I would like to create this layout in Silverlight. The text need to wrap
I need a textbox that only allows an IP address. I can create this
i need to create a chart similar to this: link text Do you have
I need to create a json message like this: { success:true, count:3, data: [
I need to create a function which rounds decimal numbers like this: Round($32.95, 0)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.