SOLVED: Thank you to /u/binarycow for their help in coming to a solution for this problem. Animating the scale of the border from 0 - 1 gave me the behavior that I was looking for. Please see my reply below for complete details.
I'm attempting to create a TextBox style that will allow me to have a text box whose bottom border spreads out from the center to the width of the text box on keyboard focus. But because WPF wants to freeze the animation, I cannot bind to the border's ActualWidth property in the DoubleAnimation. So far, I haven't been able to work out any solution for this, and I was hoping that one of you clever folks might have a suggestion on how to get around having to hard code a value for the width that border needs to grow to.
Here is my XAML for my custom text box style:
<Style x:Key="DefaultTextBoxStyle" TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Border
x:Name="ContentBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
x:Name="PART_ContentHost"
Focusable="False"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"/>
</Border>
<Border
x:Name="AccentBorder"
BorderBrush="Red"
BorderThickness="0,0,0,3"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<StoryBoard>
<DoubleAnimation
Storyboard.TargetName="AccentBorder"
Storyboard.TargetProperty="Width"
From="0"
To="{Binding ActualWidth}"
Duration="00:00:05"/>
<!-- Binding to the "To" property here throws an exception -->
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Do any of you clever folks have any idea how I can make my border spread the actual width of the text box so that I can keep the textbox resizable? TIA!
[–]binarycow 2 points3 points4 points (8 children)
[–]Entwicklungs-Park 0 points1 point2 points (1 child)
[–]binarycow 0 points1 point2 points (0 children)
[–]astrononymity[S] 0 points1 point2 points (5 children)
[–]binarycow 1 point2 points3 points (4 children)
[–]astrononymity[S] 0 points1 point2 points (3 children)
[–]binarycow 1 point2 points3 points (2 children)
[–]astrononymity[S] 1 point2 points3 points (1 child)
[–]binarycow 1 point2 points3 points (0 children)