• wp7下如何动态创建ListBox


     例如我们可以这样设定Listbox

    1 <ListBox x:Name="LB1">
    2 <ListBox.ItemTemplate>
    3 <DataTemplate>
    4 <StackPanel Width="50">
    5 <TextBlock Text="{Binding Name}"></TextBlock>
    6 </StackPanel>
    7 </DataTemplate>
    8 </ListBox.ItemTemplate>
    9 </ListBox>

      

    TextBlock textBlock = new TextBlock();
    textBlock.Text = "测试数据";
    StackPanel stackPanel = new StackPanel();
    stackPanel.Children.Add(textBlock);
    grid1.Children.Add(textBlock);
    grid1.Children.Add(stackPanel);

      

    <Style x:Key="horizontalListBoxStyle" TargetType="ListBox">

    <!--容器模板-->
    <Setter Property="ItemsPanel">
    <Setter.Value>
    <ItemsPanelTemplate>
    <StackPanel Orientation="Horizontal"<!--横向-->
    VerticalAlignment="Center"
    HorizontalAlignment="Center"/>
    </ItemsPanelTemplate>
    </Setter.Value>
    </Setter>

    <!-- item模板 -->
    <Setter Property="ItemTemplate">
    <Setter.Value>
    <DataTemplate>

    <!-- 这里设置自己定义的控件和显示-->
    <StackPanel Orientation="Horizontal">

                  
    <TextBlock Padding="5,0,5,0"
    Text
    ="{Binding FirstName}" />
    <TextBlock Text="{Binding LastName}" />
    </StackPanel>
    </DataTemplate>
    </Setter.Value>
    </Setter>
    </Style>

      

  • 相关阅读:
    javascript之DOMReady
    JQuery之proxy实现绑定代理
    javascript之数据推送
    javascript之高级函数应用思想
    函数的四种调用方式
    javascript多线程简介
    数组之迭代应用
    Git快速上手 : Tortoise工具使用
    Git 服务器搭建
    Git 安装与使用(二)
  • 原文地址:https://www.cnblogs.com/jimfrank/p/2131335.html
Copyright © 2020-2023  润新知