3
有沒有辦法在運行時將大量XML/XAML加載爲WPF控件?我可以在運行時將XML/XAML轉換爲WPF控件嗎?
相關:
Can I use XamlReader.Load or InitializeFromXaml from a WPF Window, for the Window definition?
有沒有辦法在運行時將大量XML/XAML加載爲WPF控件?我可以在運行時將XML/XAML轉換爲WPF控件嗎?
相關:
Can I use XamlReader.Load or InitializeFromXaml from a WPF Window, for the Window definition?
肯定。 你想看看什麼是XamlReader類,specefically,XamlReader.Load
E.g:
string xaml =
@"<DataTemplate>
@"<TextBlock Text=""{{Binding Converter={{StaticResource templatesConverter}}, {0} }}""/>
@"</DataTemplate>";
MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(xaml));
ParserContext context = new ParserContext();
context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
DataTemplate datatemplate = (DataTemplate)XamlReader.Load(stream, context);
這聽起來像它正是我要找的。謝謝。 – 2010-02-24 04:33:16