【发布时间】:2009-08-16 22:27:10
【问题描述】:
我正在尝试构建一个使用 5 个 XAMLS 的 Silverlight 应用程序。 第一个“Page.xaml”包含一个带有 4 个按钮的菜单和一个用于接收每个 XAML 内容的 Canvas。每个内容 XAML 都有 2 个故事板:“entrada”(“进入部分”动画)和“saida”(部分结束动画)。
我遇到以下问题: 菜单位于 Page.xaml 中。我希望每个按钮在单击时开始“saida”故事板,并且当故事板完成播放时,它会加载另一个 XAML 的新内容(由菜单选择)。当我尝试这样做时,Visual Studio 不断告诉我“'ContentCanvas' 在当前上下文中不存在”对于每个内容 XAML。
这是我的 Page.xaml.cs:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightPagingSystemProject
{
public partial class Page : UserControl
{
String secao = "home";
Section1 s1 = new Section1();
Section2 s2 = new Section2();
Section3 s3 = new Section3();
public Page()
{
// Required to initialize variables
InitializeComponent();
Link1.MouseLeftButtonDown += new MouseButtonEventHandler(Link1_MouseLeftButtonDown);
Link2.MouseLeftButtonDown += new MouseButtonEventHandler(Link2_MouseLeftButtonDown);
Link3.MouseLeftButtonDown += new MouseButtonEventHandler(Link3_MouseLeftButtonDown);
}
private void Link1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (secao == "home")
{
ContentCanvas.Children.Remove(s1);
ContentCanvas.Children.Remove(s2);
ContentCanvas.Children.Remove(s3);
ContentCanvas.Children.Add(s1);
}
else
{
ContentCanvas.saida.Begin();
}
}
private void Link2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (secao == "home")
{
ContentCanvas.Children.Remove(s1);
ContentCanvas.Children.Remove(s2);
ContentCanvas.Children.Remove(s3);
ContentCanvas.Children.Add(s2);
}
else
{
ContentCanvas.saida.Begin();
}
}
private void Link3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (secao == "home")
{
ContentCanvas.Children.Remove(s1);
ContentCanvas.Children.Remove(s2);
ContentCanvas.Children.Remove(s3);
ContentCanvas.Children.Add(s3);
}
else
{
ContentCanvas.saida.Begin();
}
}
}
}
这是我的 XAML 部分。都是一样的。
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightPagingSystemProject
{
public partial class Section3 : UserControl
{
public Section3()
{
// Required to initialize variables
InitializeComponent();
Section3LayoutRoot.Loaded += new RoutedEventHandler(Section1LayoutRoot_Loaded);
saida.Completed += new EventHandler(saida_Completed);
}
void saida_Completed(object sender, EventArgs e)
{
this.Parent.ContentCanvas.Children.Remove(s1);
this.Parent.ContentCanvas.Children.Remove(s2);
this.Parent.ContentCanvas.Children.Remove(s3);
this.Parent.ContentCanvas.Children.Add(secao);
}
void Section1LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
entrada.Begin();
}
}
}
感谢您的帮助!
【问题讨论】:
标签: silverlight xaml