我正在编写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


基础教程推荐
- windows Docker运行asp.net core代码 2023-09-26
- C# List的赋值问题的解决 2023-06-22
- 如何在不使用C#驱动程序指定过滤器的情况下替换mongodb中的对象? 2023-11-09
- C#多线程之线程同步 2023-05-25
- c#-WPF ComboBox作为System.Windows.Media.Colors 2023-11-12
- C#对集合进行排序 2023-05-25
- C#实现跑马灯效果的示例代码 2023-07-05
- c# – 在Windows 8 Store应用程序中移动到输入/返回的下一个控件 2023-09-20
- .NetCore3.1配置AutoMapper-(int转枚举Description) 2023-09-28
- C#先判断是否存在再创建文件夹或文件与递归计算文件夹大小 2023-06-27