Silverlight - 如何合并用户控件和母版页
我是 Silverlight 的新手... 我已经创建了一个用户控件,并希望在 MainPage.xaml 中使用它,请让我知道该控件的语法(如果是,则为 Xaml 语法)...
我还可以创建 MasterPage 类型的控件并使用 Silverlight 中的所有用户控件吗? 如果是,那么请让我知道该代码片段或解释所有这些的任何链接...
提前谢谢...
I m novice to Silverlight...
I have created a usercontrol and want to consume that in MainPage.xaml, pls let me know the syntex ( Xaml syntex if n e ) for that...
also Can I create a MasterPage sort of control and use all user controls in Silverlight ?
If yes then pls let me know the code snippet for that as well or any link where all these are explained...
Thx in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从 XAML 的任何其他部分使用 UserControl,请执行以下操作: 在 MainPage.xaml 中,首先必须添加本地命名空间。在该部分中
,添加以下内容:
如果您使用 VS2008/VS2010 或 Blend,这将主要为您自动完成。 (这些点表明那里有很多不相关的代码)
一旦您引用了本地名称空间。您可以像这样添加其他自定义用户控件:
同样,如果 xmlns:local 部分正确,这将为您自动完成。
值得一试的是Expression Blend。它主要是一个拖/放/点/单击界面,将为您执行这些半复杂的 XAML 操作。
Silverlight 中的一个类似于 ASP.NET MasterPage 的想法是控件模板。我不会在这里详细介绍,因为这篇文章解释得很好: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control- templates-to-customize-a-control-s-look-and-feel.aspx
或者,假设您正在构建一个包含几个页面的窗口。您想要创建一些镶边和菜单,无论您正在查看窗口上的哪个页面,这些镶边和菜单都是一致的。您可以创建一个用户控件作为其他用户控件的“框架”。该框架包含镶边和菜单,并且它是其他用户控件的容器。
这里有很多方法可供选择。由你决定。 :)
To use a UserControl from any other part of your XAML do this: In your MainPage.xaml, first you have to add the local namespace. In the
part, add the following:
This will be mostly auto-completed for you if you use VS2008/VS2010 or Blend. (The dots are there are an indicator that there is a lot of code there that is irrelevant)
Once you have a reference to the local namespace. You can add your other custom usercontrol like so:
Again, this will be autocompleted for you if you got the xmlns:local part right.
Something that is worth checking out is Expression Blend. It is mostly a drag/drop/point/click interface that will do these sort of semi-complicated XAML operations for you.
An idea in Silverlight that is similar to ASP.NET's MasterPage are control templates. I'm not going into detail here, because this article explains it quite well: http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx
Alternatively, assume you were building a window that has a few pages. You want to create some chrome and a menu that is consistent no matter which page on the window you were looking at. You can create a UserControl that is the "frame" for your other UserControls. This frame contains the chrome and the menu, and it is a container for your other UserControls.
There are lots of methods to choose from here. Up to you. :)