Created
January 23, 2015 05:16
-
-
Save battleguard/cdf6b48d6a7bfd7c01e5 to your computer and use it in GitHub Desktop.
Proper Style Inheritance in WPF
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
| <Application x:Class="WpfApplication1.App" | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
| xmlns:controls="clr-namespace:WpfApplication1.Controls" | |
| StartupUri="MainWindow.xaml"> | |
| <Application.Resources> | |
| <Style TargetType="{x:Type Control}" x:Key="MetroControl"> | |
| <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/> | |
| </Style> | |
| <Style TargetType="{x:Type Label}" BasedOn="{StaticResource MetroControl}"/> | |
| <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MetroControl}"/> | |
| <Style TargetType="{x:Type controls:CircleButton}" BasedOn="{StaticResource MetroControl}"/> | |
| <Style TargetType="{x:Type Window}" BasedOn="{StaticResource MetroControl}" x:Key="MetroWindow"> | |
| <Setter Property="Foreground" Value="Red"/> | |
| <Setter Property="FontFamily" Value="arial"/> | |
| <Setter Property="FontWeight" Value="Bold"/> | |
| </Style> | |
| <Style TargetType="{x:Type Window}" BasedOn="{StaticResource MetroWindow}"/> | |
| </Application.Resources> | |
| </Application> |
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
| <Window x:Class="WpfApplication1.MainWindow" | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
| xmlns:controls="clr-namespace:WpfApplication1.Controls" | |
| xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" | |
| xmlns:attachedProperties="clr-namespace:WpfApplication1.AttachedProperties" | |
| Title="MainWindow" Height="350" Width="525" Style="{StaticResource MetroWindow}"> | |
| <StackPanel> | |
| <Label Content="Test Label"/> | |
| <Button Content="Test Button"/> | |
| <TextBlock Text="Test TextBlock" Background="BlueViolet"/> | |
| <controls:CircleButton Click="ButtonBase_OnClick"> | |
| <i:Interaction.Behaviors> | |
| <attachedProperties:PopupButtonTestBehavior PopupPlacement="MousePoint" PopupHorizontalOffset="20"> | |
| <attachedProperties:PopupButtonTestBehavior.Popup> | |
| <StackPanel Width="100" Height="100" Background="Black"> | |
| <TextBlock Text="Textblock"/> | |
| <Label Content="Label"/> | |
| <Button Content="Button"/> | |
| </StackPanel> | |
| </attachedProperties:PopupButtonTestBehavior.Popup> | |
| </attachedProperties:PopupButtonTestBehavior> | |
| </i:Interaction.Behaviors> | |
| </controls:CircleButton> | |
| </StackPanel> | |
| </Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment