0

I a trying to implement a shape for two buttons that have a style from Application.Resource, which looks like this:

  <Style TargetType="Button">

        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="#00FFFFFF"/>
        <Setter Property="Foreground" Value="WhiteSmoke"/>
        <Setter Property="FontFamily" Value="Miryad Pro"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="Button">
                    <Border x:Name="ButtonBorder" 
              CornerRadius="3" 
              BorderThickness="2" 
              Background="#33FFFFFF"  
              BorderBrush="#00FFFFFF"
              RenderTransformOrigin="0.5,0.5">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="1.7*"/>
                            </Grid.RowDefinitions>
                            <ContentPresenter x:Name="ButtonContentPresenter"
                            VerticalAlignment="Center"  
                            HorizontalAlignment="Center" 
                            Grid.RowSpan="2" />
                        </Grid>

                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="RenderTransform" TargetName="ButtonBorder">
                                <Setter.Value>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="0.9" ScaleY="0.9"/>
                                    </TransformGroup>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>


                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

The button I am trying to re-shape has this code:

 <Button x:Name="kontakInterface_btn" VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="40" Height="90" Margin="0,20,0,200"     Click="kontakInterface_btn_Click">

            <Button.Background>
                <VisualBrush>
                    <VisualBrush.Visual>
                        <Canvas>
                            <Path Opacity="0.3" Fill="#ffffffff" Data="F1 M 8.126,171.916 L 58.216,160.074 C 62.411,158.889 65.125,149.942 65.125,147.337 L 65.125,32.680 C 65.125,30.074 61.053,20.469 58.216,19.943 L 8.126,8.496"/>
                        </Canvas>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Button.Background>




            <Image Source="C:\Users\PID Projekt I5\Documents\Visual Studio 2015\Projects\ArduinoSMS_sender\ArduinoSMS_sender\Ikone\directory-icon.png"/>

        </Button>

What do I need to override or change/add in order for the re-shaping code to work? XAML is really a pain in the ass for me.

someone1
  • 73
  • 12

2 Answers2

0

I added a property to the button that magically made it work:

Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"

I used this to remove the background of buttons.

someone1
  • 73
  • 12
0

I may have misunderstood your issue but if you simply want to apply the style to your Button, you could give it an x:Key:

<Style x:Key="myButtonStyle" ... >

...and use the StaticResource markup extension to apply it on any button:

<Button x:Name="kontakInterface_btn" Style="{StaticResource myButtonStyle}">

If you don't specify an x:Key, the Style should be automatically applied to all Button elements that are in the same scope as the Style. Please refer to MSDN for information about how styling and templating works in WPF: https://msdn.microsoft.com/en-us/library/ms745683(v=vs.110).aspx

mm8
  • 163,881
  • 10
  • 57
  • 88