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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:47:19+00:00 2026-06-13T07:47:19+00:00

I was making a UserControl when I found this strange phenomena. If I use

  • 0

I was making a UserControl when I found this strange phenomena. If I use C# code to place a GroupBox in the UserControl’s template and then make any SetResourceReference call on the GroupBox, suddenly the GroupBox inherits the foreground of TemplateParent (my UserControl).

So far I have found the following requirements for this situation:

  • UserControl base type does not matter
  • Affected template child must be a GroupBox (but not necessarily the first template child)
  • The foreground of the GroupBox may be explicitly set in the template, overriding the inherit
  • Must be using some sort of reference call from the GroupBox
  • Only the Foreground property seems to be affected

Here is my sample code:

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="350">
    <Window.Resources>
        <Thickness x:Key="TestPadding">5</Thickness>
        <Style TargetType="{x:Type GroupBox}">
            <Setter Property="Foreground" Value="Red" />
            <Setter Property="Background" Value="Orange" />
        </Style>
    </Window.Resources>
    <Grid>
        <my:TestControl Foreground="Blue" Background="Purple" />
    </Grid>
</Window>

TestControl.cs:

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Markup;

namespace WpfApplication1
{
    public class TestControl : UserControl
    {
        public TestControl()
        {
            FrameworkElementFactory group = new FrameworkElementFactory(typeof(GroupBox));
            group.SetValue(GroupBox.ContentProperty, "My Child");
            group.SetResourceReference(GroupBox.MarginProperty, "TestPadding");
            this.SetValue(TestControl.TemplateProperty, new ControlTemplate(typeof(TestControl)) { VisualTree = group });
        }
    }
}

What do you guys think, is this a bug that I should report to Microsoft?

  • 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-13T07:47:21+00:00Added an answer on June 13, 2026 at 7:47 am

    I have contacted the Microsoft WPF Development Team. They acknowledge this as a bug, but have prioritised it as low and not likely to be fixed.

    My work around for this example:
    Use another control to take the *.SetResourceReference call to perform padding, instead of the GroupBox.

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

Sidebar

Related Questions

Im making a user selection userControl for my WPF C# project. I did make
I'm making a custom webcam user control. I use Microsoft Expression Encoder, and set
Making an adobe flex ui in which data that is calculated must use proprietary
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I'm going to be making a user control for person information, I will then
I'm making a usercontrol which is a file manager (cut ,copy ,paste .. etc)
I am making a Excel Addin in VS2010. The following code work fines if
I have a usercontrol in ASP.Net featuring a button that I use to postback.
I'm making a UserControl in Windows Phone 7 and i want that when the
I've been working in asp.net webforms and I've been making a UserControl that depends

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.