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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:06:08+00:00 2026-05-29T07:06:08+00:00

So I have a class; lets use the ScrollViewer class as an example. It

  • 0

So I have a class; lets use the ScrollViewer class as an example. It has a dependency property called Content which accepts anything of type System.Object, great!

Let’s say I derive a class from ScrollViewer, lets call it ZoomScrollViewer, it adds some basic zooming and panning using the mouse with a keyboard press. It also adds a dependency property of it’s own, AutoscaleContent.

Now, I want to be able to put a ZoomScrollViewer into a UI window, but I only want it to accept a Canvas as it’s content. Naturally, I go about creating a ZoomScrollViewer<T> class.

However, how can I change the Content property so that only accepts elements of type <T>? Can I override the dependency property? I got a little confused and tried:

    public new T Content
    {
        get { return (T)base.Content; }
        set { base.Content = value; }
    }

But of course this makes it no longer a dependency property, so all the XAML code fails when I set up the bindings.

Edit: It should also be noted that I’ve taken a look at using:

ZoomScrollViewer.ContentProperty.OverrideMetadata(typeof(ZoomScrollControl2<T>), new PropertyMetadata(...?));

To see if I could do anything using that, but it seems you can only override the default value, unless I’m missing something?

Update: I’ve now tried using the following:

public class ZoomScrollControl2<T> : ZoomScrollViewer where T : FrameworkElement
{
    static ZoomScrollControl2()
    {
        ContentProperty.OverrideMetadata(typeof(ZoomScrollControl2<T>), new FrameworkPropertyMetadata(typeof(ZoomScrollControl2<T>)));
    }
}

public class CanvasZoomControl : ZoomScrollControl2<Canvas>
{
}

Which I thought would work, but it still seems to accept a Content of any type.

Update: In short I’m not sure if what I want to do is even possible, so I’ve marked the discussion as the answer, even though it isn’t an answer per-se.

  • 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-29T07:06:09+00:00Added an answer on May 29, 2026 at 7:06 am

    I suggest to try that approach as it suggested by this MSDN article.

    It should override the referal type, so you can refer to it using derived type.

    Dependency Property visibility is not made esplicit in .NET Framework for derived types, as searching right property among the types tree has a cost in terms of performance, and considering that we use DP on UI binding, it can lead to non desirable performance issues.

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

Sidebar

Related Questions

Lets say, for example, that I have a class that requires the use of
I have an ActiveRecord class - lets call it comments - which has an
Lets say you have a class SomeClass which has its own implementation of toString()
I have a class A which has a private method called a(). I have
Lets say we have a class with a property called PetsName. If it is
To keep things simple, lets say I have a Node class, each node has
I have a pointer to a given class. Lets say, for example, the pointer
Lets say I have a jquery plugin called widget which can be used on
So lets say I have a class called Post that contains an IList I
I have a code in which I use a pointer to a class that

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.