故事板在代码隐藏中不可用

发布于 2024-10-06 13:02:50 字数 1310 浏览 3 评论 0原文

为什么我使用 WPF 时无法访问情节提要。在 Silverlight 中,完全相同的代码也可以工作。

VB

Public Class UserControl1

    Private Sub UserControl1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
        Me.storyboardBlend.Begin()
    End Sub
End Class

XAML 隐藏代码:

 <UserControl x:Class="UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

        <Image x:Name="imgOn" Source="/OUTPUT%20-%20WPF01;component/Images/Disk.png" />
        <Grid.Resources>
            <Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
                <DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
            </Storyboard>

        </Grid.Resources>
    </Grid>
</UserControl>

Why can I not access to the storyboard when using WPF. In Silverlight, the exact same code works.

Codebehind VB

Public Class UserControl1

    Private Sub UserControl1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
        Me.storyboardBlend.Begin()
    End Sub
End Class

XAML:

 <UserControl x:Class="UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

        <Image x:Name="imgOn" Source="/OUTPUT%20-%20WPF01;component/Images/Disk.png" />
        <Grid.Resources>
            <Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
                <DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
            </Storyboard>

        </Grid.Resources>
    </Grid>
</UserControl>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾性傲以野 2024-10-13 13:02:51

现在可以使用字符串作为故事板的键。但我仍然无法访问下一步的动画参数。

XAML 部分:

            <Grid.Resources>
            <Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
                <DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
                <DoubleAnimation x:Name="AnimationOpacityOff" Storyboard.TargetName="imgOff" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
                <DoubleAnimation x:Name="AnimationOpacitOnGlow" Storyboard.TargetName="imgOnGlow" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
            </Storyboard>

        </Grid.Resources>

Hack in Codebehind 不起作用:

Private _Checked As Boolean
Public Property Checked As Boolean
    Get
        Return _Checked
    End Get
    Set(ByVal value As Boolean)
        _Checked = value

        Dim storyboard As Storyboard = LayoutTextImage.Resources("storyboardBlend")
        storyboard.Stop()
        If _Checked = True Then

            Dim Anim As DoubleAnimation
            Anim = storyboard("AnimationOpacityOn")
            Anim.To = 1

            Anim = Me.FindResource("AnimationOpacityOff")
            Anim.To = 0

            Anim = Me.FindResource("AnimationOpacityOnGlow")
            Anim.To = 1


            'Dim storyboard As Storyboard = Me.FindResource("storyboardBlend")
            storyboard.Begin()

        Else
            Dim Anim As DoubleAnimation
            Anim = Me.FindResource("AnimationOpacityOn")
            Anim.To = 0

            Anim = Me.FindResource("AnimationOpacityOff")
            Anim.To = 1

            Anim = Me.FindResource("AnimationOpacityOnGlow")
            Anim.To = 0

            storyboard.Begin()

        End If
    End Set
End Property

To use a string as key works now for the storyboard. But I have still no access to the animation parameter which is the next step.

XAML part:

            <Grid.Resources>
            <Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
                <DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
                <DoubleAnimation x:Name="AnimationOpacityOff" Storyboard.TargetName="imgOff" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
                <DoubleAnimation x:Name="AnimationOpacitOnGlow" Storyboard.TargetName="imgOnGlow" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
            </Storyboard>

        </Grid.Resources>

Hack in Codebehind which is not working:

Private _Checked As Boolean
Public Property Checked As Boolean
    Get
        Return _Checked
    End Get
    Set(ByVal value As Boolean)
        _Checked = value

        Dim storyboard As Storyboard = LayoutTextImage.Resources("storyboardBlend")
        storyboard.Stop()
        If _Checked = True Then

            Dim Anim As DoubleAnimation
            Anim = storyboard("AnimationOpacityOn")
            Anim.To = 1

            Anim = Me.FindResource("AnimationOpacityOff")
            Anim.To = 0

            Anim = Me.FindResource("AnimationOpacityOnGlow")
            Anim.To = 1


            'Dim storyboard As Storyboard = Me.FindResource("storyboardBlend")
            storyboard.Begin()

        Else
            Dim Anim As DoubleAnimation
            Anim = Me.FindResource("AnimationOpacityOn")
            Anim.To = 0

            Anim = Me.FindResource("AnimationOpacityOff")
            Anim.To = 1

            Anim = Me.FindResource("AnimationOpacityOnGlow")
            Anim.To = 0

            storyboard.Begin()

        End If
    End Set
End Property
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文