为什么访问我的Storyboard x:名称在Silverlight中工作但在WPF中不起作用?

为什么访问我的Storyboard x:名称在Silverlight中工作但在WPF中不起作用?,第1张

概述以下 WPF代码获取错误:当前上下文中不存在名称“zipButtonOut”. 但是,相同的代码在Silverlight中工作,如我在此演示:http://tanguay.info/web/index.php?pg=codeExamples&id=65 我需要对WPF代码做什么才能访问Window.Resources中的Storyboard?我在WPF UserControl中尝试了它,但是得到了 以下 WPF代码获取错误:当前上下文中不存在名称“zipbuttonOut”.

但是,相同的代码在Silverlight中工作,如我在此演示:http://tanguay.info/web/index.php?pg=codeExamples&id=65

我需要对WPF代码做什么才能访问Window.Resources中的Storyboard?我在WPF UserControl中尝试了它,但是得到了同样的错误.

XAML:

<Window x:Class="TestDataGrID566.Test1"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    title="Test1" Height="300" WIDth="300">    <Window.Resources>        <Storyboard x:name="zipbuttonOut" x:Key="zipbuttonOut">            <DoubleAnimation Storyboard.Targetname="buttonContinue"Storyboard.TargetProperty="WIDth"From="0" To="300" Duration="0:0:.2"></DoubleAnimation>            <DoubleAnimation Storyboard.Targetname="buttonContinue"Storyboard.TargetProperty="Height"From="2" To="50" Duration="0:0:.4"></DoubleAnimation>        </Storyboard>    </Window.Resources>    <GrID x:name="LayoutRoot" Background="White">        <StackPanel HorizontalAlignment="Center" margin="20">            <button x:name="buttonBegin" Content="Click here to begin" Background="Green" Click="buttonBegin_Click"/>            <button x:name="buttonContinue" margin="0 70 0 0" WIDth="160" Height="2" FontSize="18" Background="Yellow"Content="Click here to continue" Visibility="Collapsed"></button>        </StackPanel>    </GrID></Window>

后台代码:

using System.windows;namespace TestDataGrID566{    public partial class Test1 : Window    {        public Test1()        {            InitializeComponent();        }        private voID buttonBegin_Click(object sender,RoutedEventArgs e)        {            buttonBegin.Visibility = Visibility.Collapsed;            buttonContinue.Visibility = Visibility.Visible;            //zipbuttonOut.Begin(); //GETS ERROR: The name 'zipbuttonOut' does not exist in the current context.        }    }}
解决方法 我不知道为什么它在Silverlight中有效,但是在WPF控件中,添加到资源集合中的x:名称不在后面的代码中.它们可以通过它们的x:Key通过Resources集合访问,因此您可以删除x:name属性并在代码后面的行中添加以下代码行,这些代码将被注释掉,并且它将起作用(取消注释)当然有问题的一行):

Storyboard zipbuttonOut = (Storyboard)Resources["zipbuttonOut"];

请注意,这需要以下using语句:

using System.windows.Media.Animation;
总结

以上是内存溢出为你收集整理的为什么访问我的Storyboard x:名称在Silverlight中工作但在WPF中不起作用?全部内容,希望文章能够帮你解决为什么访问我的Storyboard x:名称在Silverlight中工作但在WPF中不起作用?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1000883.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存