<Border Name="ItemBorder" Margin="5 5 0 5" BorderBrush="Black" BorderThickness="1" Height="75" Width="75">
<Border.Background>
<SolidColorBrush x:Name="ItemBorderBrush" Color="LightBlue"/>
</Border.Background>
<ContentPresenter/>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="someEvent">
<BeginStoryboard>
<Storyboard TargetName="ItemBorderBrush" TargetProperty="Color" Duration="0:0:1" >
<!--Storyboard TargetName="ItemBorder" TargetProperty="Background.Color" Duration="0:0:1"> -->
<ColorAnimation To="White"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
I’ll try to explain my question clearly. The Storyboard Target name, when it is “ItemBorder” (the commented out line) works intermittently. Sometimes I get an error that the name “ItemBorder” cannot be found in the scope.
I decided to follow a style from an MSDN example of this, and change the color property directly on the brush, instead of having the target of the storyboard be the border, and changing the color of the border’s brush by property (the commented out line). This seems to work.
However, Name="ItemBorderBrush" does not compile because Name is not a property of SolidColorBrush so I use x:Name="ItemBorderBrush" Both Name and x:Name are accepted for the Border. Why is this?
What does the x: mean (how is x:Name different from Name), and why would having the Name property of border only work with the storyboard sometimes?
The
x:prefix is simply setting an attribute from a seperate namespace:So, the reason that
Nameandx:Nameboth work on Border is because Border has a property called Name. It also supports the XAML Intrinsic usage ofx:Name(which is what WPF uses to create the named instance of the class).However, SolidColorBrush doesn’t have the property called Name so it only supports the XAML Intrinsic usage of
x:Name.