ComboBox/ListBox - 未记录的功能?
ComboBox/ListBox - an undocumented feature?
今天,由于一个打字错误,我设法生成了以下内容xaml:
<ListView>
first line<Button>second line</Button>the third<system:String>the fourth</system:String>
</ListView>
这将编译并生成一个四行列表:
这也适用于 ListBox、ItemsControl 和 ComboBox。
我的问题:您知道 Microsoft 是否在任何地方记录了这一点吗?我以前从未见过这样的 xaml 工作。
您描述的所有项目都继承自 ItemsControl. The ItemsControl MSDN 文档有一个示例,其中将多种类型的控件添加到 ListBox 中,这与您将项目添加到 ListView 的方式非常相似。
来自 MSDN 的相关 XAML:
<!--Create a ListBox that contains a string, a Rectangle,
a Panel, and a DateTime object. These items can be accessed
via the Items property.-->
<ListBox xmlns:sys="clr-namespace:System;assembly=mscorlib"
Name="simpleListBox">
<!-- The <ListBox.Items> element is implicitly used.-->
This is a string in a ListBox
<sys:DateTime>2004/3/4 13:6:55</sys:DateTime>
<Rectangle Height="40" Width="40" Fill="Blue"/>
<StackPanel Name="itemToSelect">
<Ellipse Height="40" Fill="Blue"/>
<TextBlock>Text below an Ellipse</TextBlock>
</StackPanel>
<TextBlock>String in a TextBlock</TextBlock>
<!--</ListBox.Items>-->
</ListBox>
今天,由于一个打字错误,我设法生成了以下内容xaml:
<ListView>
first line<Button>second line</Button>the third<system:String>the fourth</system:String>
</ListView>
这将编译并生成一个四行列表:
这也适用于 ListBox、ItemsControl 和 ComboBox。
我的问题:您知道 Microsoft 是否在任何地方记录了这一点吗?我以前从未见过这样的 xaml 工作。
您描述的所有项目都继承自 ItemsControl. The ItemsControl MSDN 文档有一个示例,其中将多种类型的控件添加到 ListBox 中,这与您将项目添加到 ListView 的方式非常相似。
来自 MSDN 的相关 XAML:
<!--Create a ListBox that contains a string, a Rectangle, a Panel, and a DateTime object. These items can be accessed via the Items property.--> <ListBox xmlns:sys="clr-namespace:System;assembly=mscorlib" Name="simpleListBox"> <!-- The <ListBox.Items> element is implicitly used.--> This is a string in a ListBox <sys:DateTime>2004/3/4 13:6:55</sys:DateTime> <Rectangle Height="40" Width="40" Fill="Blue"/> <StackPanel Name="itemToSelect"> <Ellipse Height="40" Fill="Blue"/> <TextBlock>Text below an Ellipse</TextBlock> </StackPanel> <TextBlock>String in a TextBlock</TextBlock> <!--</ListBox.Items>--> </ListBox>