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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:25:03+00:00 2026-05-25T16:25:03+00:00

i have a trouble and i need your help. Here’s my code: public class

  • 0

i have a trouble and i need your help. Here’s my code:

public class CircleElement : ContentControl
{

public ContentControl me;
private FrameworkElement _parent;

public CircleElement()
{
  if (_parent != null)
  {
    me = (ContentControl)_parent.FindResource("CircleRes");
    me.Style = (Style)_parent.FindResource("CircleStyle");
  }

}

The CircleElement inherits the ContentControl and I would like to assign the resource “CircleRes” and the style “CircleStyle” to it. Something like:

this = (ContentControl)_parent.FindResource("CircleRes");
this.Style = (Style)_parent.FindResource("CircleStyle");

This thing is not allowable.So to get around this problem I instantiated the ContentControl me element; but the code is a little messy!! How to get it more “elegant” ???

Thanks in advance

Paolo

  • 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-25T16:25:04+00:00Added an answer on May 25, 2026 at 4:25 pm

    Your requirement is a little strange but it is achievable in multiple ways…

    Instead of having another content control (i.e. me) why not set this control’s Content itself?

        this.Content
               = (ContentControl)_parent.FindResource("CircleRes"); 
        ((ContentControl)(this.Content)).Style
               = (Style)_parent.FindResource("CircleStyle"); //*** Potential problem
    

    Problem: The Potential problem statement is marked this way because your code (and mine too) sets the style "CircleStyle" to "CircleRes" resource by reference.

    How? me or ((ContentControl)(this.Content)) is nothing but "CircleRes" resource!

    This means if "CircleRes" is referred in some other place, it will carry the "CircleStyle" as its own style along with it. And if you set some new Style to "CircleRes" somewhere else then it will overwrite the Style of "CircleRes" wherever is used, including the above code (where intended style is "CircleStyle")

    Solution: Use ContentTemplate instead. Templates don’t cause a visual’s by instance reference.

    So actually you should have a DataTemplate (say “CircleResTemplate”) and set that as ContentTemplate to CircleElement class.

       this.ContentTemplate
           = (DataTemplate)_parent.FindResource("CircleResTemplate");
       this.Style
           = (Style)_parent.FindResource("CircleStyle"); 
    

    Let me know if this answers your question.

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

Sidebar

Related Questions

I have trouble when designing classes like this class C1 { public: void foo();
I have some trouble writing some code (I might be tired), so I need
please I need your help with a Linq expression: I have nested objects with
I have trouble using sed. I need to replace some lines in very deprecated
I have trouble with the following piece of code. When I go through with
I have trouble finding way to correctly refactor this code so that there would
I am having trouble understanding this code. All I really need is to modify
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble using Perl grep() with a string that may contain chars that
I have trouble defining a trigger for a MySQL database. I want to change

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.