我有一个简单的用户控件,其中包含一个TextBox
。当TextBox
获得焦点时,我想改变用户控件的颜色。以下是我的代码:
<UserControl x:Class="OutLookContactList.ContactSearchControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="root" MinHeight="30" Loaded="UserControl_Loaded">
<UserControl.Resources>
<Style x:Key="searchTextBoxStyle" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
<Setter TargetName="root" Property="Background" Value="{StaticResource OnMouseOverColor}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
但是我遇到了“TargetName属性不能在样式Setter上设置”的错误。当文本框获得焦点时,我该如何设置用户控件的背景颜色?
非常感谢!