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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:26:29+00:00 2026-05-13T14:26:29+00:00

I have a problem changing the focus to some button on xaml. The code

  • 0

I have a problem changing the focus to some button on xaml.
The code I am attemps to do it looks as follows (if some conditions are fulfilled then the focus should be set to the button. The strange is that for test purposes I’m also chaning the background of the button and this property is set each time the conditions are fulfilled. How can I set the default button or set the focus on that button?

<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
  <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
      <Condition Binding="{Binding Path=SomeProperty1.Count, Converter={StaticResource IntegerToBooleanConverter}}" Value="True"/>
      <Condition Binding="{Binding Path=SomeProperty2, Converter={StaticResource NullToBoolConverter}}" Value="False"/>
      <Condition Binding="{Binding Path=SomeProperty3.Count, Converter={StaticResource IntegerToBooleanConverter}}" Value="True"/> 
    </MultiDataTrigger.Conditions>
    <Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}"/>
    <Setter Property="IsDefault" Value="True"/> 
    <Setter Property="Background" Value="Green"/>
  </MultiDataTrigger>
</Style.Triggers>

additionally i would like to write that SomeProperty1 and SomeProperty2 are set only if I click on the specific button. As I can see these buttons have then the focus.

  • 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-13T14:26:30+00:00Added an answer on May 13, 2026 at 2:26 pm

    The problem is that FocusManager.FocusedElement controls only the local focus within a FocusScope. Since the Button is not its own FocusScope it has no effect. You need to call the Focus() method, which requires you to write some code.

    You could do the obvious and write an event handler, or you could do the non-obvious and create an attached property “MyFocusManager.ForceFocus” that, when transitioning from false to true, sets FocusManager.FocusedElement. This is done with a PropertyChangedCallback, something like this:

    public class MyFocusManager
    {
      public static bool GetForceFocus .... // use "propa" snippet to fill this in
      public static void SetForceFocus ....
      public static DependencyProperty ForceFocusProperty = DependencyProperty.RegisterAttached("ForceFocus", typeof(bool), typeof(MyFocusManager),  new UIPropertyMetadata
        {
          PropertyChangedCallback = (obj, e) =>
          {
            if((bool)e.NewValue && !(bool)e.OldValue & obj is IInputElement)
              ((IInputElement)obj).Focus();
          }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are working with any PowerPoint file formats (including… May 17, 2026 at 12:52 am
  • Editorial Team
    Editorial Team added an answer You need to convert your rectangle to your view's coordinate… May 17, 2026 at 12:52 am
  • Editorial Team
    Editorial Team added an answer As I explained in an answer to your previous question… May 17, 2026 at 12:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a problem with changing my spring/hibernate application from MySql to SQL Server.
I have a problem with jQuery Validator. I want to use required property on
I have a text area and a add button on a form. By default
I have the problem that I must map a fixed URL parameter that contains
I have a picklist web interface: a pair of select elements with a pair
I have a situation when I want to change the selected value of a
I've read through some of the other posts and followed their suggested advice but
We have a Win32 application that hosts the .NET runtime and opens up .NET
I have a JList inside a Scrollpane. If you click on the list and
I have an app that downloads a very large file (over 50MB). Unfortunately I'm

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.