Moataz Aahmed Mohammed
Moataz Aahmed Mohammed

Reputation: 1297

How to bind polygon points in specific style at runtime wpf ,windows?

I have this code for style

<Window.Resources>
    <Style  x:Key="Mystyle" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid >
                        <Polygon Name="poly"  Points="0,0 0,100 50,200"
                         Fill=" TemplateBinding Background}"                            
                        <ContentPresenter HorizontalAlignment="Center"
                                      VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</Window.Resources>
<Grid>
    <Button Name="b1" Style="{StaticResource Mystyle }"></Button>

</Grid>

I need to set points for polygon in style tag not static but dynamic based on some calculation how can i bind points to polygon. example I have this

PointCollection pc=this.CalculatePolygonPoints(new Point(0,0), 100,Orientation.Flat);

How can i bind this pc to my polygon dynamic

Upvotes: 0

Views: 1533

Answers (1)

Erti-Chris Eelmaa
Erti-Chris Eelmaa

Reputation: 26298

Why dont you just create new dependency property(of a type PointCollection?) and bind Polygon's Points property against it? Then do your calculations when needed(@code-behind), and UI will automatically understand.

Here is an example(using ObservableCollection); http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/1293d4cb-87b3-4cdc-97e3-ae2f41caf2d4/

Upvotes: 2

Related Questions