获得异常wpf

时间:2017-11-25 15:25:23

标签: c# wpf animation textbox

我收到此异常,我试图在鼠标悬停在enter code here

上时更改tex textbox tbox宽度

这是例外:

  

无法设置'宽度'在...上的财产   ' System.Windows.Controls.TextBox'用一个   ' System.Windows.Media.Animation.DoubleAnimation&#39 ;.详情请见   内在异常。

<Style TargetType="TextBox">
    <Setter Property="BorderBrush" Value="#248FB3" />
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="AcceptsReturn" Value="True"/>     
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="true">

            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="250" >
                        </DoubleAnimation>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
            <Trigger.ExitActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width"/>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.ExitActions>
        </Trigger>

        <Trigger Property="IsKeyboardFocusWithin" Value="true">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard> 
                        <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="250"/>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
            <Trigger.ExitActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width"/>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.ExitActions>
        </Trigger>

    </Style.Triggers>

</Style>

1 个答案:

答案 0 :(得分:0)

您必须在Width元素上设置TextBox,或在From设置DoubleAnimation属性。如果您未设置任何一个,它将获取Width属性的默认值Double.NaN,因此它不知道从哪里开始。