skip to Main Content

I’ve been working with WPF for a couple of days now and I’ve pre-designed my project in photoshop. Now, I’m on my way to WPF development. The problem, however, is the following: Is there a way to block windows’ themes? What I mean by that is that e.g. when creating a button it’ll be styled the way I want it to be, but the hover/click events will still overwrite the design, which ultimately looks completely wicked. In a really bad way.
I guess, what I might be looking for is an equivalent to the wildcard accessible in css…

2

Answers


  1. Yes, you can override any of the windows themes by applying your own control templates. The hover/click events are part of these templates.

    If you make the control templates part of a resource, you can then reuse them across all your controls.

    The default templates can be found here: http://msdn.microsoft.com/en-us/library/aa970773(v=vs.110).aspx

    Button styles and templates can be found here : http://msdn.microsoft.com/en-us/library/ms753328(v=vs.110).aspx

    Login or Signup to reply.
  2. I understand you problems so if you want to make a complete customize button according to you then you can use Template property of button.

    You can write some style code in windows resources section.

    <Window x:Class="DataBinding.ButtonTemplating"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ButtonTemplating" Height="300" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Background" Value="#373737" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="FontSize" Value="15" />
            <Setter Property="SnapsToDevicePixels" Value="True" />
    
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border CornerRadius="4" Background="{TemplateBinding Background}">
    
                                <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
    
                        </Border>
    
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#E59400" />
                                <Setter Property="Foreground" Value="White" />
    
                            </Trigger>
    
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="OrangeRed" />
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Button Width="200" Height="50" VerticalAlignment="Top">WPF</Button>
    

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search