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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:33:05+00:00 2026-05-19T16:33:05+00:00

In WPF, how do you set the target of a label so that the

  • 0

In WPF, how do you set the target of a label so that the access key will set focus on the control inside a ContentControl?

I am using MVVM and so I do not want to add any code to the code behind in order to solve this.

I have already tried setting the path to “Content” and at runtime an exception was thrown because there is no converter for the data type which is set to the content of the ContentControl. If I don’t set the path, then focus is set to the ContentControl itself.

<Label Target="{Binding ElementName=_myContentControl, Path=Content}"/>
  • 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-19T16:33:06+00:00Added an answer on May 19, 2026 at 4:33 pm

    Use GotFocus event.

    <Label Target="myContentControl" >_Content</Label>
    <ContentControl x:Name="myContentControl" GotFocus="myContentControl_GotFocus">
    

     

    private void myContentControl_GotFocus(object sender, RoutedEventArgs e)
    {
        var cc = sender as ContentControl;
        if (cc != null && cc.Content is UIElement)
            ((UIElement)cc.Content).Focus();
    }    
    

    Another solution using the separated class FocusBehavior:

    class FocusBehaviour : Behavior<ContentControl>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.GotFocus += new System.Windows.RoutedEventHandler(AssociatedObject_GotFocus);
        }
    
        void AssociatedObject_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            var c = this.AssociatedObject.Content as UIElement;
            if (c != null)
                c.Focus();
        }
    
        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.GotFocus -= new System.Windows.RoutedEventHandler(AssociatedObject_GotFocus);
        }
    }
    

    XAML:

    <ContentControl x:Name="myContentControl">
        <i:Interaction.Behaviors>
            <local:FocusBehaviour />
        </i:Interaction.Behaviors>
    </ContentControl>
    

    This way requires a dll that is called System.Windows.Interactivity and is installed with Expression Blend SDK.

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

Sidebar

Related Questions

I wanna implement an interface(Add behavior) for set of WPF usercontrols. I'm using MVVM
I set the datasource for a WPF dxg:GridControl to that of a hard coded
How can we set border and background color in the WPF grid control ,
Is there a way to set the .Text property of the Wpf ComboBox control
In WPF,I can set the background of a stack panel using the below code
Quite often I will set up WPF UserControl with a declarative DataContext: <UserControl...> <UserControl.DataContext>
I have a WPF application in PRISM architecture. I have a user-control (view) that
I have a GridViewResource that localize the telerik wpf gridview and set in the
Short version: WPF seems to always set a local value when using an IValueConverter
I have a WPF data trigger that is set to fire when a value

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.