Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:17:11+00:00 2026-06-14T15:17:11+00:00

I do have a control template for WPF button. Within the template I can

  • 0

I do have a control template for WPF button. Within the template I can use the Fillcolor and Backcolor of the button. But is it possible to define a third color that can be used in the template and later on in a real button?

Here an example of a circular button. I would like to add a color for the ToggleButton.IsChecked state.

<ControlTemplate x:Key="MyButtonTemplate" TargetType="{x:Type ToggleButton}">
    <Grid>
        <Ellipse x:Name="outerCircle" Width="Auto" Height="Auto" StrokeThickness="4" Fill="White" Stroke="Gray"/>
        <Label x:Name="content" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/>
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsChecked" Value="True">
            <Setter TargetName="outerCircle" Property="Fill" Value="{Binding Path=Foreground, RelativeSource='{RelativeSource TemplatedParent}'}"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter TargetName="outerCircle" Property="Fill" Value="LightGray"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter TargetName="outerCircle" Property="Fill" Value="{Binding Path=Foreground, RelativeSource='{RelativeSource TemplatedParent}'}"/>
            <Setter TargetName="content" Property="Foreground" Value="Gray"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:17:11+00:00Added an answer on June 14, 2026 at 3:17 pm

    I am not sure wether or not you want to bind this to a property or just use a brush resource, Here is an example using a Resource:

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <SolidColorBrush x:Key="ControlPressedColor">#FF211AA9</SolidColorBrush >
            <ControlTemplate x:Key="MyButtonTemplate" TargetType="{x:Type ToggleButton}">
                <Grid>
                    <Ellipse x:Name="outerCircle" Width="Auto" Height="Auto" StrokeThickness="4" Fill="White" Stroke="Gray"/>
                    <Label x:Name="content" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="outerCircle" Property="Fill" Value="{StaticResource ControlPressedColor}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="outerCircle" Property="Fill" Value="LightGray"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="outerCircle" Property="Fill" Value="{Binding Path=Foreground, RelativeSource='{RelativeSource TemplatedParent}'}"/>
                        <Setter TargetName="content" Property="Foreground" Value="Gray"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Window.Resources>
        <Grid>
            <ToggleButton Template="{StaticResource MyButtonTemplate}"  Height="50" Width="50"></ToggleButton>
        </Grid>
    </Window>
    

    Base on the clarification that you wanted to be able to set the property on the ToggleButton you will need to use a Dependecy Property here is a quick example:

    Custom Control

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication1
    {
    
        public class CustomControl2 : System.Windows.Controls.Primitives.ToggleButton 
        {
            public static readonly DependencyProperty myFillColorProperty = DependencyProperty.Register("myFillColor",typeof(SolidColorBrush),typeof(System.Windows.Controls.Primitives.ToggleButton));    
            static CustomControl2()
            {
                DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl2), new FrameworkPropertyMetadata(typeof(CustomControl2)));
            }
    
            public SolidColorBrush myFillColor
            {
                get { return (SolidColorBrush)GetValue(myFillColorProperty); }
                set { SetValue(myFillColorProperty, value); }
    
            }
        }
    }
    

    MainWindow.xaml

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my ="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <ControlTemplate x:Key="MyButtonTemplate" TargetType="{x:Type ToggleButton}">
                <Grid>
                    <Ellipse x:Name="outerCircle" Width="Auto" Height="Auto" StrokeThickness="4" Fill="White" Stroke="Gray"/>
                    <Label x:Name="content" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="outerCircle" Property="Fill" Value="{Binding Path=myFillColor, RelativeSource='{RelativeSource TemplatedParent}'}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="outerCircle" Property="Fill" Value="LightGray"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="outerCircle" Property="Fill" Value="{Binding Path=Foreground, RelativeSource='{RelativeSource TemplatedParent}'}"/>
                        <Setter TargetName="content" Property="Foreground" Value="Gray"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Window.Resources>
        <Grid>
            <my:CustomControl2 myFillColor="Red" Template="{StaticResource MyButtonTemplate}"  Height="50" Width="50"></my:CustomControl2>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf cusotm control derived from combobox System.Windows.Controls.ComboBox the control template is
So I have this WPF style: <Style x:Key=SmallLinkButton TargetType=Button> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=Button>
I have re-styled a textbox using a control template. The styling works well but
Is it possible to have a listbox displaying its items with a control template
I have a button control which its template is stilyzed in an external resource
In WPF most controls have MouseUp and MouseDown events (and the mouse-button-specific variations) but
Within a Listbox control I have a Data Template which consists of text and
In WPF I have a stack panel whose items control defines a data template.
I have a WPF button style below: <Style x:Key=myButtonStyle TargetType={x:Type Button}> <Setter Property=Template> <Setter.Value>
I have just been learning about how styles and control templates in WPF can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.