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

  • Home
  • SEARCH
  • 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 7969251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:12:27+00:00 2026-06-04T07:12:27+00:00

i am trying to create one dependency property in a class called "FocusBehaviour" that

  • 0

i am trying to create one dependency property in a class called
"FocusBehaviour" that is in Class library.. I have added the
namespaces like below.. But it showing error in line 1) return
(bool)control.GetValue(FocusFirstProperty);

error: System.windows.Controls.Control Doesn’t have a method
‘GetValue" that accepts the First argument of type
System.windows.Controls.Control. 2) The same error is coming from
SetValue() also…below that… 3) Control control = dpObj as Control;
error:Cann’t convert System.DependencyObject To
System.windows.Controls.Control

I Also Added the WindowsBase Reference..

  using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace MyOrgBI
{
    public static class FocusBehavior:DependencyObject
    {

        public static readonly DependencyProperty FocusFirstProperty = 
        DependencyProperty.RegisterAttached("FocusFirst", 
                                            typeof(bool),
                                            typeof(Control),
                                            new PropertyMetadata(OnFocusFirstPropertyChanged));

    public static bool GetFocusFirst(Control control)
    {
        return (bool)control.GetValue(FocusFirstProperty);
    }
    public static void SetFocusFirst(Control control, bool value)
    {
        control.SetValue(FocusFirstProperty, value);
    }
    static void OnFocusFirstPropertyChanged(DependencyObject dpObj, DependencyPropertyChangedEventArgs args)
    {
        Control control = dpObj as Control;
        if (control == null || !(args.NewValue is bool))
        {
            return;
        }
        if ((bool)args.NewValue)
        {
            control.Loaded += (sender, e) => control.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
        }
    }
}

}

Previously I created a dependency property in a WpfApplication project. It worked fine but when I create one in another class library it shows this error.

Why these errors Coming ? And how should I write this code?

  • 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-04T07:12:27+00:00Added an answer on June 4, 2026 at 7:12 am

    You need to add a reference to the WindowsBase Assembly. DependencyObject is located there.

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

Sidebar

Related Questions

I am trying to create a program that has one tableview and when you
i am trying to create a Radio button using Cakephp like the one the
I'm trying to create a custom set of classes that can be added to
Hi guys i am trying to create one simple make file and execute in
I am trying to create a situation where one or none of a grouping
I am trying to create a dictionary from 2 lists where one list contains
I'm trying to create a table with Listview and one of the fields I'm
I'm trying to create a simple sinatra app with one page containing a text
I'm trying to create a drop down button and its almost working except one
I am trying to create a little helper application, one scenario is file duplication

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.