以下 WPF 代码出现错误:当前上下文中不存在名称“zipButtonOut”。
但是,正如我在这里演示的那样,相同的代码在 Silverlight 中有效:http ://tanguay.info/web/index.php?pg=codeExamples&id=65
我必须对 WPF 代码做什么才能访问 Window.Resources 中的情节提要?我也在 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.
}
}
}