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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:58:21+00:00 2026-05-23T19:58:21+00:00

WPF control-derived class has a composition of non-WPF control-derived class . The latter class,

  • 0
  1. WPF control-derived class has a composition of non-WPF control-derived class. The latter class, say Inner, should trigger an Outer class WPF DependencyProperty change.

  2. Essential invariant is that my Inner class shouldn’t force any WPF namespaces to use whereby, Inner is part of API of a dll I am creating. So Inheritance from any WPF class is not appropriate solution.

What could be the best (or at least arbitraty) way to implement a callback from non-.NET derived class to a WPF-Control class to change a DependencyProperty object.

Some hypothetical callback mechanisms found:

  • c# delegates and c# events.

Can’t solve this, becouce it is thrown a runtime exception

The calling thread cannot access this object because a different thread owns it.

when a callback mechanism tries to modify Background property (a DependancyProperty object I think is the key, or at least .NET defined property).

I guess that c# delegates doesn’t work in single-threading manner – however, i didn’t find this fact while reading c# documentation.

(One solution is through .NET Dispatcher class and Invoke(), but it seems too arbitrary and possibly slow – isn’t any more WPF-friendly way?)

  • I had read about Routed events and DependencyProperties

in WPF documentation (however had’t tested this yet), but it seems Routed event cant help (because my Inner class isn’t part of a VisualTree) and I should’t inherit from DependencyObject.

I read (I suppose) everything relevant to my problem. I’m sorry if some similar kind of question had been asked, I would be glad if you direct me to that thread, if the problem essence is the same.

Simplified example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.Timers;

namespace WpfApplication4
{
    internal class Rect:ContentControl
    {
        Inner inner = new Inner();

        public Rect()
        {
            inner.Rotate += new Inner.RotateEventHandler(rotated);
        }

        public void rotated(object sender, RotateEventArgs args)
        {
            Background = Brushes.Blue;                            //Run time error
            VisualTransform = new RotateTransform(args.Angle);  //Run time error
        }
    }

    public class Inner
    {
        Timer timer = new Timer(200);

        public Inner()
        {
            timer.Enabled = true;
            timer.Elapsed +=new ElapsedEventHandler(elapsed);
        }

        public delegate void RotateEventHandler(object sender, RotateEventArgs args);
        public event RotateEventHandler Rotate;

        public void elapsed(object sender, ElapsedEventArgs e)
        {
            RotateEventArgs args = new RotateEventArgs();
            args.Angle = args.Angle + 45;
            OnRotate(args);
        }

        protected void OnRotate(RotateEventArgs e)
        {
            if (e != null)
            {
                Rotate(this, e);
            }
        }
    }

    internal class RotateEventArgs
    {
        private double angle = 0;

        public double Angle
        {
            set { angle = value; }
            get { return angle; }
        }
    }
}
  • 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-23T19:58:22+00:00Added an answer on May 23, 2026 at 7:58 pm

    You can make use of DispatchTimer instead of Timer. Have the DispatchTimer in the Rect class itself.

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

Sidebar

Related Questions

I am creating a custom WPF control that let's say for simplicity sake has
I have a WPF control, that has a list of Investors, and in the
I have a custom control derived from Button: class MyControl : Button{} And suppose,
I am creating a class that derives from the WPF RichTextBox control and I
I've got a Windows Forms control that I'm wrapping with a WindowsFormsHost -derived class
I have a WPF user control that is dervied from UserControl class. MouseLeftButtonDown is
I am creating a custom control derived from the one of the Standard WPF
I have my own derived WPF DataVisualization chart control and within that control, I
I am working on a custom control for WPF and Silverlight. This control has
I want to create custom WPF control that has a single child control inside.

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.