Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to change the background of the StackPanel control when any child element has focus?

$
0
0

Hello folks!

I need to change the background of the StackPanel control when any element within the StackPanel has focus. I am executing the code snippet below. The code works fine with elements within the Grid control named "main". It doesn't work when I focus an element within the Grid control named "header".

<StackPanel x:Name="techReportStackPanel" Width="250" Background="{Binding ColorBrush}" ><StackPanel.Style><Style TargetType="{x:Type StackPanel}"><Style.Triggers><DataTrigger Binding="{Binding ElementName=techReportStackPanel, Path=IsKeyboardFocusWithin}" Value="True"><Setter Property="Background" Value="Gray" /><Setter Property="Opacity" Value=".5" /></DataTrigger></Style.Triggers></Style></StackPanel.Style><Grid x:Name="header"><TextBlock x:Name="headerColumn" Text="{Binding Name}" Style="{StaticResource ColumHeader}"/><Button Visibility="{Binding ElementName=headerColumn, Path=Text, Converter={StaticResource delButtonVisibilityConverter}}" Command="{Binding DelCommand}" Content="x" ToolTip="{l:Translate TechReportDeleteToolTip}"/></Grid><Grid x:Name="main"><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition Width="*" /></Grid.ColumnDefinitions><wpftoolkit:WatermarkTextBox Grid.Column="0" Style="{StaticResource OrdinaryTextbox}" Watermark="{l:Translate LengthLabel}" ToolTip="{l:Translate BoreholeSpacingInRow}" Text="{Binding BoreholeSpacingInRow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=F2, Converter={StaticResource zeroToEmptyDoubleConverter}}" /><wpftoolkit:WatermarkTextBox Grid.Column="1" Style="{StaticResource OrdinaryTextbox}" Watermark="{l:Translate WidthLabel}" ToolTip="{l:Translate BoreholeSpacingBetweenRow}" Text="{Binding BoreholeSpacingBetweenRow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=F2, Converter={StaticResource zeroToEmptyDoubleConverter}}" /></Grid></StackPanel>
Any advice and suggestions will be greatly appreciated!

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>