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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:16:50+00:00 2026-05-24T09:16:50+00:00

I have created my own control in WPF. Initially I created it as a

  • 0

I have created my own control in WPF. Initially I created it as a usercontrol but found the preferred way to do this is to create a class which inherits from control and then place my respective xaml in a control template inside Generic.xaml.

This worked fine when it was in my exe but when I moved it to a dll the border disappeared from my control. My control is based off a textbox and is a pretty much a copy and paste of the textbox’s control template with the addition of a button the user can click.

I’ve identified the relevant part of the control template that is not working which is the BorderBrush="{TemplateBinding Border.BorderBrush}" bit below as well as the next line.

<Style TargetType="{x:Type local:ButtonBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ButtonBox}">
                <mwt:ListBoxChrome 
                        Background="{TemplateBinding Panel.Background}"
                        BorderBrush="{TemplateBinding Border.BorderBrush}"
                        BorderThickness="{TemplateBinding Border.BorderThickness}"
                        RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}"
                        RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}"
                        Name="Bd"
                        SnapsToDevicePixels="True">

I understand template binding but I don’t understand why we are binding to Border.BorderBrush. Where is the border that we are binding to? The visual tree shows no border that is part of my control. If I replace these 2 lines with hard coded values then I get a border. I suspect there might be something missing from the dll that the exe has such as a style or something that applies to Border??

Thanks in advance for any replies and anyone who took the time to read.
Cheers,
Michael

  • 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-05-24T09:16:51+00:00Added an answer on May 24, 2026 at 9:16 am

    I finally got this sorted out. To answer my first question “Why are we using Border.BorderBrush in this code when there is no border defined in the control template”:

    BorderBrush="{TemplateBinding Border.BorderBrush}"
    

    The border in Border.BorderBrush is there because the dependency property is defined on the Border class. Although Control has a dependency property of BorderBrush the property is actually defined in Border. ie, this is how is it defined in Border

    BorderBrushProperty = DependencyProperty.Register("BorderBrush", typeof(Brush), typeof(Border), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender | FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(Border.OnClearPenCache)));
    

    and this is how it is used in Control

    BorderBrushProperty = Border.BorderBrushProperty.AddOwner(typeof(Control), new FrameworkPropertyMetadata(Border.BorderBrushProperty.DefaultMetadata.DefaultValue, FrameworkPropertyMetadataOptions.None));
    

    The key point here is that Control does not define its own dependency property of BorderBrush, instead it uses AddOwner to associate itself with the existing dependency property. This is why it is defined as Border.BorderBrush in the control template even though the textbox does not have a border in its control template.

    The answer to my second question “where is this value set”, is that it is set in the textbox’s default style. I can get a look at the default style for a textbox by doing this:

                var style = (Style)Application.Current.TryFindResource(typeof(TextBox));
                if (style == null) return;
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                StringBuilder sb = new StringBuilder();
                XmlWriter writer = XmlWriter.Create(sb, settings);
                XamlWriter.Save(style, writer);
                MessageBox.Show(sb.ToString());
    

    Once we run this code we can see in the style were both properties are hard coded. This seems odd to me but this is apparently the way it has been done.

      <Setter Property="Border.BorderBrush">
        <Setter.Value>
          <LinearGradientBrush StartPoint="0,0" EndPoint="0,20" MappingMode="Absolute">
            <LinearGradientBrush.GradientStops>
              <GradientStop Color="#FFABADB3" Offset="0.05" />
              <GradientStop Color="#FFE2E3EA" Offset="0.07" />
              <GradientStop Color="#FFE3E9EF" Offset="1" />
            </LinearGradientBrush.GradientStops>
          </LinearGradientBrush>
        </Setter.Value>
      </Setter>
      <Setter Property="Border.BorderThickness">
        <Setter.Value>
          <Thickness>1,1,1,1</Thickness>
        </Setter.Value>
      </Setter>
    

    After I copy pasted that into the style for my control everything worked as expected.

    Simple hey? :-)))

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

Sidebar

Related Questions

I have created my own Attached Property like this: public static class LabelExtension {
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have create my own NSOpenGLView class, right now the data that i want
I have successfully created my own virtual path provider to load a user control
I have created my own ControlTemplate for Button, like this: <Style x:Key=LightButtonStyle TargetType={x:Type ButtonBase}>
I have my own custom control derived from System.Windows.Forms.TreeView which is present on the
I have my own Control1 which is dynamically added as child control to Control2
I have created a user control in silver-light. I will use this control in
I have my own derived WPF DataVisualization chart control and within that control, I
I have created my own Tree implementation for various reasons and have come up

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.