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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:24:12+00:00 2026-05-16T10:24:12+00:00

I am using a custom default button attached behaviour (as defined here: Silverlight 4

  • 0

I am using a custom default button attached behaviour (as defined here: Silverlight 4 Default Button Service).

I am able to bind this successfully in XAML, but in a nested user control, in code behind the following does not work:

public partial class MyNestedUserContol{

/// a DP for storing the name of the default button, used in the ElementName binding
public string DefaultButton {
    get { return (string)GetValue(DefaultButtonProperty); }
    set { SetValue(DefaultButtonProperty, value); }
}
public static readonly DependencyProperty DefaultButtonProperty =
    DependencyProperty.Register("DefaultButton", typeof(string), typeof(TeamReferenceFieldEditor), new PropertyMetadata(null));

...

private void CreateCustomControls(){
    ...
    TextBox tb = new TextBox();
    ...
    AddDefaultButtonBinding(tb);
    ...
}

private void AddDefaultButtonBinding(Control control) {
    Binding binding = new Binding();
    binding.ElementName = this.DefaultButton;
    control.SetBinding(DefaultButtonService.DefaultButtonProperty, binding); }

...
}

How should I create the binding for this in code?
Thanks,
Mark

  • 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-16T10:24:13+00:00Added an answer on May 16, 2026 at 10:24 am

    Ultimately this will be a problem in namescopes. The value assigned to ElementName probably doesn’t exist in the same namescope that the TextBox belongs to.

    Have you considered simply using:-

     private void MainPage_Load(object sender, RoutedEventArgs e)
     {
       LayoutRoot.AddHandler(UIElement.KeyUpEvent, LayoutRoot_KeyUp, true)
     }
    
     private void LayoutRoot_Keyup(object sender, KeyEventArgs e)
     {
       if (e.Key == Key.Enter)
       {
         // invoke default operation here
       }
     }
    

    I’ve read through your other question and the blog article. Its seems like a bad smell to have to attach strange properties to various controls like a textbox to implement a default button, which ultimately has nothing to do with the textbox.

    It would be a better pattern to attach a property on the button which is to be declared the default (or to create a sub-class of Button called DefaultButton) and to have that co-operate with the containing UserControl, Page or ChildWindow to watch for the enter key. This would not then have to involve other controls not directly related to delivering this functionality.

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

Sidebar

Related Questions

I am using custom model binder in ASP.NET MVC 2 that looks like this:
here's my issue. I have defined custom themes and styles, so as to customize
i am using custom cell in uitableview cell.I am giving button on the right
I'm displaying custom images on a map (instead of the default pins) using the
I am using the following code for a custom back button with title in
I am using category android:name=android.intent.category.HOME category android:name=android.intent.category.DEFAULT to override the HOME button behavior and
I'm using Jquery mobile and doing some custom stuff. The default collapsible object just
i'm working on custom radio button. it works fine(as it is defined in options.xml)
When using custom assemblies in a visual studio project. How does one check in
I'm aware of using custom configuration values for my custom services, but what if

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.