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 8170861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:16:31+00:00 2026-06-06T21:16:31+00:00

I try to create a ControlTemplate for my Label like this : <Style TargetType={x:Type

  • 0

I try to create a ControlTemplate for my Label like this :

<Style TargetType="{x:Type Label}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Label}">
                <Grid x:Name="LayoutRoot" Background="White">
                    <Rectangle Height="30" HorizontalAlignment="Left" Margin="10" 
                               Stroke="transparent" 
                               VerticalAlignment="Top" Width="3" 
                               Fill="#FF259FED" />

                    <ContentPresenter HorizontalAlignment="Left" Margin="17,0,0,0"  RecognizesAccessKey="True" 
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                      VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Foreground" Value="#7A7E81" />
    <Setter Property="FontWeight" Value="Bold" />
</Style>

I want to fill color of rectangle when i create my control, like this for example :

<Label Content="Prénom" VerticalAlignment="Top" CouleurRectangle="#FF259FED" />

So, how can I change Property “Fill” in my controlTemplate to set dynamicly color of rectangle when i create control ?

thank’s a lot.

Edit : this is the solution , i create a new class who inherit from Label like this :

    Public Class LblTitreChamp
    Inherits Label

    Public Shared ReadOnly CouleurProperty As DependencyProperty =
        DependencyProperty.Register("CouleurRectangle", GetType(SolidColorBrush), GetType(LblTitreChamp))
    ''' <summary>Propriété pour insérer une couleur au début du Label</summary>
    Public Property CouleurRectangle As SolidColorBrush
        Get
            Return GetValue(CouleurProperty)
        End Get
        Set(ByVal value As SolidColorBrush)
            SetValue(CouleurProperty, value)
        End Set
    End Property

End Class

then, in my COntrolTemplate :

<Style TargetType="{x:Type local:LblTitreChamp}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:LblTitreChamp}">
                    <Grid x:Name="LayoutRoot" Background="White">
                        <Rectangle Height="30" HorizontalAlignment="Left" Margin="10" 
                                   Stroke="transparent" 
                                   VerticalAlignment="Top" Width="3" 
                                  Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Label}}, Path=CouleurRectangle}"/>

                        <ContentPresenter HorizontalAlignment="Left" Margin="17,0,0,0"  RecognizesAccessKey="True" 
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                          VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Foreground" Value="#7A7E81" />
        <Setter Property="FontWeight" Value="Bold" />
    </Style>

and finally, to creat a new label :

<my:LblTitreChamp Content="ID" VerticalAlignment="Top" CouleurRectangle="Black" />

thank’s a lot for you 🙂

  • 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-06T21:16:34+00:00Added an answer on June 6, 2026 at 9:16 pm

    hi set Fill={TemplateBinding CouleurRectangle} .Hope this will help. And i Expect that you have created a custom Label class That inherit from Label and has DependencyProperty CouleurRectangle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to try create something like Zend's Server Pagecache. What I want to
At the moment I have this: try{ // Create file FileWriter fstream = new
I am following this tutorial . All is going well until I try create
I currently try to create classes for a paint-like WPF application. I have to
This is my XAML makiing a Style where the Button looks like an Ellipse.
I try create delegate type using an Expression class, but when I try create
I currently try to create classes for a paint-like WPF application. I have to
I try create method for get the connection string value but without value for
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,

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.