.net 如何在 XAML 中填充 List<string>?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1508035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Populate a List<string> in XAML?
提问by MrGreggles
Here's another easy XAML question for you guys:
这是给你们的另一个简单的 XAML 问题:
I can populate a 'complex' list okay in XAML like:
我可以在 XAML 中填充“复杂”列表,例如:
<local:People x:Key="family">
<local:Person Name="The Babe" Age="45"/>
<local:Person Name="Greggles" Age="41"/>
<local:Person Name="Elmo" Age=10"/>
</local:People>
But in the case of:
但在以下情况下:
public class FileNames : List<string> { }
...how are the strings added?
...如何添加字符串?
<local:FileNames x:Key="fileNames">
???
</local:FileNames>
BTW You may recongnise the example, adapted from "Programming WPF" by Chris Sells.
顺便说一句,您可能会认出这个例子,改编自 Chris Sells 的“Programming WPF”。
Thanks for your help!
谢谢你的帮助!
回答by Kent Boogaart
<local:FileNames x:Key="fileNames" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>One</sys:String>
<sys:String>Two</sys:String>
<sys:String>Three</sys:String>
</local:FileNames>
回答by Konamiman
From MSDN:
从MSDN:
<x:Array Type="sys:String"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>Hello</sys:String>
<sys:String>World</sys:String>
</x:Array>
I guess creatting a list instead of an array would be similar.
我想创建一个列表而不是一个数组是类似的。

