Live Chat Icon For mobile
Live Chat Icon

How do I change the background of my Grid layout when one of it’s children gets keyboard focus?

Platform: WPF| Category: Input and Commands.

You can change the background of the grid layout when one of its children gets keyboard focus by setting the IsKeyboardFocusWithin property. This can be done with the following code snippet,

        <Style x:Key = "GridTriggerStyle" TargetType = "Grid">
                <Trigger Property = "IsKeyboardFocusWithin" Value = "True">
                    <Setter Property = "Background" Value = "Green" />
                <Trigger Property = "IsKeyboardFocusWithin" Value = "False">
                    <Setter Property = "Background" Value = "AliceBlue" />
    <Grid Name="testGrid" Style="{StaticResource GridTriggerStyle}">
        <Button Height="30" Width="100" Content="SampleButton1"/>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.