Question

In this example property:

Data= M150.655, 39.109L10.407, 53.785L0.602, 1.309l158.026-0.806L150.655, 39.109z

How does this Data property work and use these 5 values?

<Style x:Key="ButtonStyler"

     TargetType="{x:Type Button}">
<Setter Property="Cursor"
        Value="Hand" />
<Setter Property="Template">

  <Setter.Value>
    <ControlTemplate
      TargetType="{x:Type Button}">
      <Grid>

        <Path x:Name="ButtonBG"
              Fill="Lime"
              Stroke="#000000"
              StrokeThickness="3"  

              Data="M150.655,39.109L10.407,53.785L0.602,1.309l158.026-0.806L150.655,39.109z" />
        <ContentPresenter x:Name="ContentSite"
                          Margin="20,10,20,10"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          TextBlock.FontFamily="Comic Sans MS"
                          TextBlock.FontSize="20">
          <ContentPresenter.RenderTransform>
            <TransformGroup>
              <TransformGroup.Children>
                <TransformCollection>
                  <RotateTransform Angle="-5" />
                  <ScaleTransform ScaleX="1.5"
                                  ScaleY="1" />
                  <TranslateTransform X="-35"
                                      Y="0" />
                </TransformCollection>
              </TransformGroup.Children>
            </TransformGroup>
          </ContentPresenter.RenderTransform>
        </ContentPresenter>
      </Grid>
      <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver"
                 Value="true">
          <Setter Property="Path.Fill"
                  Value="yellow"
                  TargetName="ButtonBG" />
        </Trigger>
        <Trigger Property="IsPressed"
                 Value="true">
          <Setter Property="Path.Fill"
                  Value="lime"
                  TargetName="ButtonBG" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
</Setter>
<Style.Triggers>
  <Trigger Property="IsMouseOver"
           Value="true">
    <Setter Property="RenderTransform">
      <Setter.Value>
        <TransformGroup>
          <TransformGroup.Children>
            <TransformCollection>
              <RotateTransform Angle="-5" />
              <TranslateTransform X="-5"
                                  Y="0" />
            </TransformCollection>
          </TransformGroup.Children>
        </TransformGroup>
      </Setter.Value>
    </Setter>
  </Trigger>
  <Trigger Property="IsPressed"
           Value="true">
    <Setter Property="RenderTransform">
      <Setter.Value>
        <TransformGroup>
          <TransformGroup.Children>
            <TransformCollection>
              <RotateTransform Angle="-5" />
              <TranslateTransform X="-5"
                                  Y="5" />
            </TransformCollection>
          </TransformGroup.Children>
        </TransformGroup>
      </Setter.Value>
    </Setter>
  </Trigger>
</Style.Triggers>

Was it helpful?

Solution

Data Property as associated with shapes and path geometry dont dierectly go into it, first just read the basics of path geometry then you will be able to understand data property of any shape..

OTHER TIPS

The Data is a Property of the Path object in your template...

http://msdn.microsoft.com/en-us/library/ms745814.aspx

edit:

From the msdn doco: The Data attribute string begins with the "moveto" command, indicated by M, which establishes a start point for the path in the coordinate system of the Canvas. Path data parameters are case-sensitive. The capital M indicates an absolute location for the new current point. A lowercase m would indicate relative coordinates. The first segment is a cubic Bezier curve beginning at (100,200) and ending at (400,175), drawn using the two control points (100,25) and (400,350). This segment is indicated by the C command in the Data attribute string. Again, the capital C indicates an absolute path; the lowercase c would indicate a relative path.

The second segment begins with an absolute horizontal "lineto" command H, which specifies a line drawn from the preceding subpath's endpoint (400,175) to a new endpoint (280,175). Because it is a horizontal "lineto" command, the value specified is an x-coordinate.

For the complete path syntax, see the Data reference and How to: Create a Shape by Using a PathGeometry.

Hope this helps :)

Ian

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top