0

I have made a custom suface button according this example:

<Button>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid>
                <!-- my custom shape -->
                                    <Polygon
                                     Points="400,150 100,350 100,350, 500,350"
                                     Stroke="Purple" 
                                     StrokeThickness="2"
                                     Name="L1">
                                       <Polygon.Fill>
                                          <SolidColorBrush Color="Blue" Opacity="0.4"/>
                                       </Polygon.Fill>
                    </Polygon>
                <ContentPresenter />
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>

But there is a problem with styles - there is no behaviour when touched/holded/released. Could you give me a clue how to do that?

thanks

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Lukas Hruby
  • 75
  • 10

1 Answers1

1

An example control template (found at msdn) is:

<Style TargetType="Button">
  <Setter Property="SnapsToDevicePixels" Value="true"/>
  <Setter Property="OverridesDefaultStyle" Value="true"/>
  <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
  <Setter Property="MinHeight" Value="23"/>
  <Setter Property="MinWidth" Value="75"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Border 
          x:Name="Border"  
          CornerRadius="2" 
          BorderThickness="1"
          Background="{StaticResource NormalBrush}"
          BorderBrush="{StaticResource NormalBorderBrush}">
          <ContentPresenter 
            Margin="2"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            RecognizesAccessKey="True"/>
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="IsKeyboardFocused" Value="true">
            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
          </Trigger>
          <Trigger Property="IsDefaulted" Value="true">
            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
          </Trigger>
          <Trigger Property="IsMouseOver" Value="true">
            <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
          </Trigger>
          <Trigger Property="IsPressed" Value="true">
            <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
          </Trigger>
          <Trigger Property="IsEnabled" Value="false">
            <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

As you can see you stripped out all the triggers, not to mention visual styles.

I would take that code and put your polygon in place of the ContentPresenter.

Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88
  • Those pages give examples and not the original templates, see [this question](http://stackoverflow.com/questions/1559261/control-template-for-existing-controls-in-wpf). – H.B. Mar 27 '12 at 10:04