我正在编写Windows 8.1手机运行时应用程序.我的资产中有一个包含Xaml内容的文件.当按下按钮时,我要按照文件中Xaml的定义创建Stackpanel的内容.我仔细搜索了一下,发现我们可以读取一个字符串中的Xaml文件,并将其传递...
我正在编写Windows 8.1手机运行时应用程序.我的资产中有一个包含Xaml内容的文件.当按下按钮时,我要按照文件中Xaml的定义创建Stackpanel的内容.
我仔细搜索了一下,发现我们可以读取一个字符串中的Xaml文件,并将其传递给XamlReader类,该类随后可用于将新的Xaml分配给StackPanel.我指的是here,代码也写在下面.
string xaml =
"<Ellipse Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\"
Fill=\"Red\" \"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";
object ellipse = XamlReader.Load(xaml);
//stackPanelRoot is the visual root of a Page in existing XAML markup already loaded by the appmodel
stackPanelRoot.Children.Add(ellipse as UIElement);
//walk the tree using XLinq result and cast back to a XAML type to set a property on it at runtime
var result = (from item in stackPanelRoot.Children
where (item is FrameworkElement)
&& ((FrameworkElement) item).Name == "EllipseAdded"
select item as FrameworkElement).FirstOrDefault();
((Ellipse) result).Fill = new SolidColorBrush(Colors.Yellow);
但是我的问题是XamlReader类在Windows 8.1电话运行时应用程序中不可用.我正在使用Visual Studio2013.在Windows 8.1电话运行时应用程序中找到了一个名为Windows.UI.Xaml的命名空间.
谁能指导我如何实现在Windows Phone 8.1运行时加载新Xaml的功能.
解决方法:
XamlReader在Windows Phone 8.1 Silverlight应用程序和Windows Phone 8.1 Store应用程序上均可用:
>在Windows Phone 8.1 Silverlight应用程序上:
System.Windows.Markup.XamlReader
>在Windows Phone 8.1商店中
应用:Windows.UI.Xaml.Markup.XamlReader
本文标题为:C#-在Windows 8.1运行时应用程序中动态加载Xaml
- C# AE之返回上一级和下一级的实战操作 2023-03-29
- c# 防火墙添加/删除 特定端口的示例 2023-03-14
- c# – 双击以启动Windows服务 2023-09-20
- C# StreamReader类实现读取文件的方法 2023-03-29
- 用NSSM把.Net Core部署至 Windows 服务 2023-09-26
- C#滑动验证码拼图验证功能实现(SlideCaptcha) 2023-06-04
- c# Winform 程序自动更新实现方法 2022-10-27
- C#中ManualResetEvent用法总结 2023-03-29
- C#入门之定义类成员与接口实现 2023-06-05
- VS2013创建Windows服务与调试服务的图文方法 2022-10-27