Created
November 12, 2019 22:08
-
-
Save rmarinho/663a0ff1f5d956599f230a594b6171d6 to your computer and use it in GitHub Desktop.
ButtonTemplateWithEvents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ControlTemplate TargetType="{x:Type Button}"> | |
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> | |
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> | |
<ContentPresenter.Content> | |
<StackPanel> | |
<Button Content="{TemplateBinding Content}" Click="Button_Click"></Button> | |
<Button Content="{TemplateBinding Content}" Click="Button_Click_1"></Button> | |
</StackPanel> | |
</ContentPresenter.Content> | |
</ContentPresenter> | |
</Border> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsDefaulted" Value="true"> | |
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
</Trigger> | |
<Trigger Property="IsMouseOver" Value="true"> | |
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/> | |
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/> | |
</Trigger> | |
<Trigger Property="IsPressed" Value="true"> | |
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/> | |
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/> | |
</Trigger> | |
<Trigger Property="IsEnabled" Value="false"> | |
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/> | |
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/> | |
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
<Grid> | |
<Button Content="Text" Style="{DynamicResource ButtonStyle1}" Click="Button_Click_2"></Button> | |
</Grid> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
System.Diagnostics.Debug.WriteLine("I m the template button 1"); | |
} | |
private void Button_Click_1(object sender, RoutedEventArgs e) | |
{ | |
System.Diagnostics.Debug.WriteLine("I m the template button 2"); | |
} | |
private void Button_Click_2(object sender, RoutedEventArgs e) | |
{ | |
System.Diagnostics.Debug.WriteLine("I m the main button"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I m the template button 1 | |
I m the main button | |
I m the template button 2 | |
I m the main button |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment