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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:27:36+00:00 2026-05-23T10:27:36+00:00

XAML lets me attach properties to types that are not derived from DependencyObject. For

  • 0

XAML lets me attach properties to types that are not derived from DependencyObject. For example, I could give names to the CommandBindings on a Window:

<Window.CommandBindings>
  <CommandBinding x:Name="Refresh" Command="NavigationCommands.Refresh" />
  <CommandBinding x:Name="Print" Command="ApplicationCommands.Print" />
</Window.CommandBindings>

I found mention of this possibility on MSDN (Attached Properties Overview), which states “If your class is defining the attached property strictly for use on other types, then the class does not have to derive from DependencyObject. But you do need to derive from DependencyObject if you follow the overall WPF model of having your attached property also be a dependency property.” – but I have no idea how to get at these attached properties in code.

Given the above XAML code inserted into a <Window />, how can I retrieve values of the x:Name properties from each CommandBinding?

  • 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-23T10:27:37+00:00Added an answer on May 23, 2026 at 10:27 am

    You read it backwards: you can’t apply an attached property to a non-DependencyObject. You can however define an attached property on a class not deriving from DependencyObject. Typically a static class, like FocusManager in WPF.

    x:Name is not an attached property: it’s a directive. In the common case of a FrameworkElement, it’s the same as FrameworkElement.Name. In the case of a custom class, its purpose is to define a field of the same name (which should be your case: you now have Refresh and Print fields available from code-behind). In every case (except inside a ResourceDictionary), it’s added to the current XAML namescope.

    You can use FindName on your Window to get a command binding from its name. If you really need to get the name back from the object, you can use the following piece of code to get an enumerable dictionary containing every named element in the scope:

    var dictionary = (INameScopeDictionary) NameScope.GetNameScope(yourWindow);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lets say a WeeklyViewUserControl.xaml and a DailyViewUserControl.xaml. Normally I used stuff like
XAML allows you to specify an attribute value using a string that contains curly
The XAML below does not work (the text does not change when mousing over):
I'm having trouble filtering hierarchical data that's being displayed in nested xaml templates. I've
I want to make buttons similar to those on this website. Lets say that
Okay, I have an ItemsControl in a XAML file that binds to an ObservableCollection.
This one is driving me crazy:-) Lets say I have some test xaml code:
Lets have a class: public partial class MyControl: UserControl{ private ObservableCollection<string> names = new
Lets say I have some XAML like this: <StackPanel> <TextBlock Text=Blah Blah Blah />
Let's say that I have a global variable defined in App.xaml.cs as follows: public

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.