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

  • Home
  • SEARCH
  • 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

Related Questions

I have a problem with changing my spring/hibernate application from MySql to SQL Server.
You can see the full problem here: http://users.cjb.net/syn4k/test.htm I have described the problem in
I have the problem that I must map a fixed URL parameter that contains
I have a problem with YUI 2 calendar. I activated the year selection property
I have a problem with a durable client on ActiveMQ. I am using stomp.py
I have an app that downloads a very large file (over 50MB). Unfortunately I'm
Hey guys. I'm not much of a programmer, but still need to do some
I'm having problems testing parts of my html pages with Selenium RC. If an
I face a very annoying bug in D2007 IDE : It's the second time
In my current application I want to implement ASP.Net localization with global resources. I

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.