zoukankan      html  css  js  c++  java
  • 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>

      

  • 相关阅读:
    Fbpanel-轻巧的面板措施
    Skype for Linux 1.4 Alpha 公布
    KFTPgrabber 0.8.1
    Ardour:专业的数字音频任务站
    Cinelerra:视频编纂软件
    V2EX::ING 与 INGC
    HandBrake:DVD 转换工具
    XML Copy Editor:XML 编纂器
    Abraca:XMMS2 的客户端
    KMess:MSN Messenger for KDE
  • 原文地址:https://www.cnblogs.com/jimfrank/p/2131335.html
Copyright © 2011-2022 走看看