How to animate BorderThickness in WinUI?

135 views Asked by At

My app uses WinUI 3, and I want to animate BorderThickness with a smooth transition from beginning to end. In WPF I can do this with this code:

<BeginStoryboard>
    <Storyboard>
        <ThicknessAnimation Storyboard.TargetProperty="BorderThickness" From="0" To="3" Duration="0:0:0.2" />
    </Storyboard>
</BeginStoryboard>

I tried to use this code, but it changes meaning abruptly:

<Storyboard Duration="0:0:4">
    <ObjectAnimationUsingKeyFrames 
        BeginTime="0:0:0" 
        Storyboard.TargetName="ContentPresenter" 
        Storyboard.TargetProperty="BorderThickness">
        <DiscreteObjectKeyFrame KeyTime="0:0:0">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,0,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:3">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>5,5,5,5</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>
0

There are 0 answers