x:Array的使用

时间:2022-10-24 04:21:22

x:Array是通过Items属性向使用者暴露一个类型已知的ArrayList。ArrayList中成员类型由x:Array type指明

<Window x:Class="demo_05.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="400">
    <Grid Background="LightBlue">
        <ListBox Margin="5" ItemsSource="{x:Array Type=sys:String}"/>
        <ListBox Margin="5">
            <ListBox.ItemsSource>
                <x:Array Type="sys:String">
                    <sys:String>tom</sys:String>
                    <sys:String>tim</sys:String>
                    <sys:String>victor</sys:String>
                </x:Array>
            </ListBox.ItemsSource>
        </ListBox>
    </Grid>
</Window>