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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:33:24+00:00 2026-05-22T11:33:24+00:00

I have the following in my root ResourceDictionary. The Foreground = Red part works,

  • 0

I have the following in my root ResourceDictionary. The Foreground = Red part works, but the custom attached dependency property does not get set.

I can set it manually through code, but I obviously want to avoid having to set it for every textbox. Does this work in Silverlight? I have seen some posts about doing it in WPF, and my code looks right (to me).

<Style TargetType="TextBox">
    <Setter Property="controls:TextBoxContextMenu.HasContextMenu" Value="True" />
    <Setter Property="Foreground" Value="Red" />
</Style>


/// <summary>
    /// Gets the value of the HasContextMenu attached property for a specified TextBox.
    /// </summary>
    /// <param name="element">The TextBox from which the property value is read.</param>
    /// <returns>The HasContextMenu property value for the TextBox.</returns>
    public static bool GetHasContextMenu(TextBox element)
    {
        if (element == null)
        {
            throw new ArgumentNullException("element");
        }
        return (bool)element.GetValue(HasContextMenuProperty);
    }

    /// <summary>
    /// Sets the value of the HasContextMenu attached property to a specified TextBox.
    /// </summary>
    /// <param name="element">The TextBox to which the attached property is written.</param>
    /// <param name="value">The needed HasContextMenu value.</param>
    public static void SetHasContextMenu(TextBox element, bool value)
    {
        if (element == null)
        {
            throw new ArgumentNullException("element");
        }
        element.SetValue(HasContextMenuProperty, value);
    }

    /// <summary>
    /// Identifies the HasContextMenu dependency property.
    /// </summary>
    public static readonly DependencyProperty HasContextMenuProperty =
        DependencyProperty.RegisterAttached(
            "HasContextMenu",
            typeof(bool),
            typeof(TextBox),
            new PropertyMetadata(false, OnHasContextMenuPropertyChanged));

    /// <summary>
    /// HasContextMenuProperty property changed handler.
    /// </summary>
    /// <param name="d">TextBoxContextMenu that changed its HasContextMenu.</param>
    /// <param name="e">Event arguments.</param>
    private static void OnHasContextMenuPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ 
    // code
}

I should add that the attached dependency property is defined in a class which inherits from RadContextMenu, which is a DependencyObject (I have been reading and somewhere it is suggested that this can’t work if the attached property is defined in such a class, but this seems strange)

  • 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-22T11:33:25+00:00Added an answer on May 22, 2026 at 11:33 am

    I figured it out. It was indeed due to having the attached property defined in the class I have.

    To fix it, i created a new class called TextBoxContextMenuService and put the code in there instead.

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

Sidebar

Related Questions

I have following code on http://septicsecurity.com/facebook.html It used to work, but does not work
I have the following environment: root view controller is UINavigationController a number of custom
I'm not sure what is wrong here, but I have the following conf: #
I have the following xml: <Root> <Item> <CityCode>ALV</CityCode> <AirportCode>ALV</AirportCode> <CityName>ANDORRA LA VELLA</CityName> <AirportName>Andorra La
I have created following rule in the .htaccess file located at the root of
I have the following XML: <root> <section> <item name=a> <uuid>1</uuid> </item> </section> <section> <item
I have the following xsl with me <Root> <child> <Book name=Title value=hailey /> <Book
I have the following XML Schema: <Root> <EventSet> <Event> <id> //random id </id> <time>
I have the following rule defined in the .htaccess file of my webapplication's root
I have the following XML <ns0:Root xmlns:ns0=http://Map_Sample.Input_Schema> <Number1> </Number1> <Number2>11</Number2> <Number3>12</Number3> </ns0:Root> In this

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.