silverlight,ListBox的模板

 <ListBox x:Name="listTest">
                <ListBox.Template>
                    <ControlTemplate TargetType="ListBox"> 整体的容器
                        <Grid>
                            <ItemsPresenter />
                        </Grid>
                    </ControlTemplate>
                </ListBox.Template>

                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>   items的容器

                        <my:WrapPanel ItemHeight="50" ItemWidth="150" FlowDirection="LeftToRight" >
                        </my:WrapPanel>                 
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>            
                    <DataTemplate> 数据绑定使用的每一个 item的模板
                        <Border BorderBrush="Red" BorderThickness="1">
                            <Button GotFocus="Button_GotFocus">
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding txtbUserName}"></TextBlock>
                                        <TextBox Text="{Binding txtUserName}"></TextBox>
                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

 

最终生成结果为:

<Grid>
                             <my:WrapPanel ItemHeight="50" ItemWidth="150" FlowDirection="LeftToRight" >
 <Border BorderBrush="Red" BorderThickness="1">
                            <Button GotFocus="Button_GotFocus">
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding txtbUserName}"></TextBlock>
                                        <TextBox Text="{Binding txtUserName}"></TextBox>
                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </Border>
 <Border BorderBrush="Red" BorderThickness="1">
                            <Button GotFocus="Button_GotFocus">
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding txtbUserName}"></TextBlock>
                                        <TextBox Text="{Binding txtUserName}"></TextBox>
                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </Border>
 <Border BorderBrush="Red" BorderThickness="1">
                            <Button GotFocus="Button_GotFocus">
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding txtbUserName}"></TextBlock>
                                        <TextBox Text="{Binding txtUserName}"></TextBox>
                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </Border>
 <Border BorderBrush="Red" BorderThickness="1">
                            <Button GotFocus="Button_GotFocus">
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding txtbUserName}"></TextBlock>
                                        <TextBox Text="{Binding txtUserName}"></TextBox>
                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </Border>

                        </my:WrapPanel>   

                         </Grid>

你可能感兴趣的:(silverlight)