![](/img/trans.png)
[英]How to add Multiple AppBar/CommandBar's in xaml page itself in windows phone 8.1 runtime app?
[英]load Xaml dynamically in Windows 8.1 runtime app
我正在寫一個Windows 8.1手機運行時應用程序。 我的資產中有一個文件,其中包含Xaml內容。 按下按鈕時,我想制作文件中Xaml定義的Stackpanel的內容。
我搜索了一下,發現我們可以讀取字符串中的Xaml文件並將其傳遞給XamlReader類,然后可以使用該類將新的Xaml分配給StackPanel。 我所指的方法在這里 ,代碼也在下面寫。
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 Studio 2013.我找到了一個名為Windows.UI.Xaml的命名空間,它位於Windows 8.1手機運行時應用程序中。
任何人都可以指導我如何實現在Windows Phone 8.1運行時加載新Xaml的功能。
XamlReader
適用於Windows Phone 8.1 Silverlight應用程序和Windows Phone 8.1 Store應用程序:
System.Windows.Markup.XamlReader
Windows.UI.Xaml.Markup.XamlReader
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.