角が丸い境界線で囲まれたテキストボックスがあります。どちらも背景色が同じで、1 つのデータ入力ボックスとして表示されます。ユーザーがテキストボックスをクリックすると、テキストボックスの背景と境界線の色が変わります。スタイリングが MainWindow にあるときに、これが機能しています。ただし、MainWindow の XAML からすべてのスタイリングを中央のリソース ディクショナリに抽象化しようとしています。そうすることで、ElementNameがスコープ内になくなったため、境界線の背景色を変更するDataTriggerが機能していないことがわかりました(少なくともそれが問題だと思います)。テストプロジェクト/ソリューションでこれを行うことで物事を簡素化しようとしましたが、データトリガーを機能させる方法を見つけることができないようです. XAML ファイルが 2 つあるだけです。1 つは MainWindow で、もう 1 つはリソース ディクショナリです。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary Source="/MainSkins.xaml"/>
</Window.Resources>
<Grid HorizontalAlignment="Left" Width="307" Margin="83,0,0,0">
<Border Style="{StaticResource AnimatedInputTextBoxBorder}"
Margin="10,76,10,151">
<TextBox Name="txtTransitRoutingNumber" Style="{StaticResource
AnimatedInputTextBox}"
HorizontalAlignment="Left" Height="73" Margin="9,9,0,0"
TextWrapping="Wrap" Text=""
VerticalAlignment="Top"
Width="267"/>
</Border>
</Grid>
</Window>
上記のように、 MainWindow.xaml とはまったく異なるファイルにあるリソース ディクショナリは次のとおりです。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Style x:Key="AnimatedInputTextBoxBorder" TargetType="{x:Type Border}">
<Setter Property="Background" Value="#DADADA"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="CornerRadius" Value="15"/>
<Setter Property="BorderBrush" Value="#DADADA"/>
<Style.Triggers>
<!--THIS DATA TRIGGER IS NOT WORKING-->
<DataTrigger Binding="{Binding Path=IsFocused}" Value="true">
<Setter Property="Background" Value="#C2E4F6" />
<Setter Property="BorderBrush" Value="#C2E4F6"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="AnimatedInputTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#DADADA"/>
<Setter Property="Foreground" Value="#000000" />
<Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="#C2E4F6"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
XAMLに関してはまったくの初心者なので、どんな助けも大歓迎です。