如何在XAML中设置ItemsSource?

Vis*_*hal 2 wpf xaml

我已经设置了ListBox的ItemsSource,如下所示:

<ListBox ItemsSource="{Binding abc}" />
Run Code Online (Sandbox Code Playgroud)

我想要的是

<ListBox>
    <listBox.ItemsSource>
        ?????????????
    <listBox.ItemsSource>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

Gaz*_*yer 8

<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib">

<ListBox>
<ListBox.ItemsSource>
    <x:Array Type="sys:String">
        <sys:String>1st item</sys:String>
        <sys:String>2nd item</sys:String>
    </x:Array>
<ListBox.ItemsSource>
</ListBox>

</Window>
Run Code Online (Sandbox Code Playgroud)


Ars*_*yan 5

<ListBox>
    <listBox.ItemsSource>
        <Binding Path = "abs" />
    <listBox.ItemsSource>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

  • -1 这正是OP在第一个示例中所具有的内容,但语法更详细。 (3认同)