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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:43:27+00:00 2026-06-11T05:43:27+00:00

Ok so obviously there’s more to it, but here’s the basics. This is seemingly

  • 0

Ok so obviously there’s more to it, but here’s the basics. This is seemingly such a simple thing but it’s not working.

I have a Label.
I have a TextBox.

The ZIndex of the Label = “1”
The ZIndex of the TextBox = “0”

i.e. They are on top of one another and the TextBox is invisible.

When the user clicks on the LABEL (right now Via PreviewMouseLeftButtonDown but will be a command in ViewModel after this “works”) the application should set focus to the TextBox.

Simple right? Wrong…

If I have this code…it does NOT work.

    private void inVisTxtBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            inVisTxtBox.Focus();
//            TextBox_MouseDown(sender, e);
        }

If I have this code…it DOES work

 private void inVisTxtBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            inVisTxtBox.Focus();
//            TextBox_MouseDown(sender, e);
            MessageBox.Show("This is ridiculous");
        }

And finally the XAML:

 <Ctrls:AControl x:Class="<location of class>"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:CommandControls="clr-namespace:<location of custom controls>" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid Margin="0,15,15,15">
        <!--<Button Height="50" Click="Button_Click">FOC</Button>-->
        <TextBox x:Name="inVisTxtBox" Focusable="True" Grid.ZIndex="0" Width="100" Margin="5"/>
        <Label Grid.ZIndex="1" Margin="5" Content="243234234234234" HorizontalAlignment="Left" Width="100" PreviewMouseLeftButtonDown="inVisTxtBox_PreviewMouseLeftButtonDown" 
               x:Name="KeyPress_TextBox"/>
    </Grid>
</Ctrls:AControl>

EDIT

If I make the Label into a Templated Button with a label as it’s template it works:

<Button x:Name="KeyPress_TextBox" Grid.ZIndex="1" Margin="5" Content="243234234234234" HorizontalAlignment="Left" Width="100" Click="KeyPress_TextBox_Click">
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Label Content="{TemplateBinding Content}"/>
        </ControlTemplate>
    </Button.Template>
</Button>

Why is that?

Must have something to do with the way the events route/bubble?

I have it working now by doing that…but I’m more curious what’s happening.

Also…none of the following works either:

Keyboard.Focus(inVisTxtBox);
FocusManager.SetFocusedElement(MainGrid,inVisTxtBox);
Keyboard.Focus(inVisTxtBox);
  • 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-06-11T05:43:29+00:00Added an answer on June 11, 2026 at 5:43 am

    I copied your code and it works fine for me, even with previewmouseclick, something else seems to be the problem.

    Likely throwing the message box up stops the focus from shifting to whatever it was going to shift to after the PreviewMouseLeftButtonDown event fires. Perhaps the UserControl itself is getting focus?

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

Sidebar

Related Questions

you must have seen this piece of code somewhere else too,but obviously there's no
Is there a more elegant solution for this question? I have about 70 .png
Lets say I have an equation - x^2+y^2=100 - obviously there's more than one
Obviously there must have been a programming language to write a compiler for, but
If I have the following ASP.NET code (it's not complete - obviously there's a
Here's what I'm trying to do... It's quite simple and obviously there must be
We have a 2,000,000 lines of code application in Mercurial. Obviously there is a
Potentially embarrassing question, but there is obviously something I'm missing that I want/need to
Notepad++ obviously recognizes all comments as such. Is there a way to simply delete
Obviously there are security reasons to close a wireless network and it's not fun

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.