所以,我有以下代码:
<TreeView x:Name="treeUsers">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="wpfTestBench:Group"
ItemsSource="{Binding myList }">
<Border x:Name="headerTree" Background="#FFD9D7FD" CornerRadius="3"
Padding="2" Margin="2">
<Grid Width="330" Height="20">
</Grid>
</Border>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="wpfTestBench:User">
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded}"></Setter>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
我想通过故事板更改该边框的背景,但我没有运气这样做。我尝试过使用
Storyboard.TargetName=headerTree
但我收到一条错误消息,说找不到headerTree。
编辑: 这是我目前的故事板:
<Storyboard x:Key="ChangeColorStoryboard">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="
(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Storyboard.TargetName="grid">
<EasingColorKeyFrame KeyTime="0:0:0.5" Value="#FFA3DA9A"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="
(Border.BorderBrush).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
Storyboard.TargetName="border">
<EasingColorKeyFrame KeyTime="0:0:0.5" Value="#FFA3DA9A"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="
(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Storyboard.TargetName="border">
<EasingColorKeyFrame KeyTime="0:0:0.5" Value="#FFA3DA9A"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
PS:改变所需颜色的代码不存在,因为我不知道怎么做。