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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:19:51+00:00 2026-05-25T21:19:51+00:00

I have a UserControl subclass that contains a Grid , which in turn contains

  • 0

I have a UserControl subclass that contains a Grid, which in turn contains a couple TextBlocks and a Border (which also contains a TextBlock). See code below.

    <UserControl x:Class="ProjectNS.MyUserControl"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:my="clr-namespace:ProjectNS"
       mc:Ignorable="d" 
       Height="49" Width="150" BottomResizeLocked="True" TopResizeLocked="True"  
       MoveLocks="Vertical" Margin="0,-4" Focusable="True">
        <my:MyUserControl.Resources>
            <Style x:Key="BorderStyle" TargetType="Border">
                <Setter Property="Background" Value="Blue"/>
                <Setter Property="BorderBrush" Value="Blue"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource 
                     AncestorType={x:Type my:GanttBar}}, Path=IsKeyboardFocusWithin}" 
                     Value="True">
                        <Setter Property="Background" Value="{StaticResource 
                        SelectedGanttBarBackGroundBrush}"/>
                        <Setter Property="BorderBrush" Value="{StaticResource 
                        SelectedGanttBarBorderBrush}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </my:MyUserControl.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="2*" />
                <RowDefinition Height="3*" />
                <RowDefinition Height="2*" />
            </Grid.RowDefinitions>
            <Label FontSize="8.5" HorizontalAlignment="Left"
            VerticalAlignment="Bottom" Margin="4,0,0,0" Foreground="Green" />
            <Border Grid.Row="1" CornerRadius="5" BorderThickness="1.5" Style="
            {StaticResource BorderStyle}" FocusVisualStyle="{StaticResource 
             SelectedBorderStyle}" Focusable="True" >
                <Label FontSize="10" HorizontalAlignment="Center" FontWeight="Bold" 
                 VerticalAlignment="Top" Foreground="White" Margin="0,2,0,0" />
            </Border>
            <Label HorizontalAlignment="Right" FontSize="8.5" Grid.Row="2" 
            VerticalAlignment="Top" Margin="0,0,4,0" Foreground="Red" />
        </Grid>
    </my:MyUserControl>

I’m trying to get the color of the embedded Border to change color when my UserControl receives focus, but I can’t for the life of me figure out what actually receives focus when I click on the control. I’ve tried using the GotFocus event for every control, and nothing fires once the program is running.

  • 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-25T21:19:52+00:00Added an answer on May 25, 2026 at 9:19 pm

    Use a DataTrigger on the property IsKeyboardFocusWithin. I’m not positive the exact syntax, but it should look something like this:

    <Style TargetType="{x:Type Border}">
        <Setter Property="BorderBrush" Value="Red" />
        <Style.Triggers>
    
            <!-- Will change Border color when KeyboardFocus inside Border -->
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="BorderBrush" Value="Green" />
            </Trigger>
    
            <!-- Will change Border color when UserControl contains KeyboardFocus -->
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource 
                AncestorType={x:Type local:MyUserControl}}, 
                Path=IsKeyboardFocusWithin}" Value="True">
                <Setter Property="BorderBrush" Value="Blue" />
            </DataTrigger>
    
        </Style.Triggers>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Usercontrol(TabUserControl) which contains a TabControl. The Viewmodel of that UserControl loads
I have a usercontrol which has a couple of textblocks on it <UserControl x:Class=Tester.Messenger
I have UserControl which contains a TextBox and a Button control. The Button opens
I have a UserControl which contains a TextBox . When my main window loads
I have a UserControl that exists of only two TextBlocks: <UserControl [...] x:Name=root> <StackPanel
I have a UserControl, which is basically a wrapper for a GridView that needs
I have a UserControl that allows the user to upload files and also displays
I have a usercontrol that I want to have the grid inside so I
I have a usercontrol that displays a gradient of colors which, once created will
I have a UserControl that contains an Expander : <UserControl x:Class=Client.DevicesExpander xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006

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.