window phone 开发之 ListBox控件使用
webphp
13年前
前台页面代码: <pre class="brush:c#; toolbar: true; auto-links: false;"><!--数据列表开始--> <ScrollViewer HorizontalScrollBarVisibility="Auto" BorderBrush="White" BorderThickness="1" Margin="0,120,0,0"> <StackPanel Height="450"> <!--<Border BorderBrush="Gray" BorderThickness="1">--> <Grid Margin="5,0,0,2"> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="130" Width="130" MaxWidth="150" /> <ColumnDefinition MinWidth="150" Width="150" MaxWidth="200"/> <ColumnDefinition MinWidth="150" Width="150" MaxWidth="200"/> <ColumnDefinition MinWidth="200" Width="250" MaxWidth="400"/> </Grid.ColumnDefinitions> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="0"> <TextBlock Grid.Column="0" HorizontalAlignment="Center" Text="客户名称"></TextBlock> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="1"> <TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="固定电话"></TextBlock> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="2"> <TextBlock Grid.Column="2" HorizontalAlignment="Center" Text="移动电话"></TextBlock> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="3"> <TextBlock Grid.Column="3" HorizontalAlignment="Center" Text="地址"></TextBlock> </Border> </Grid> <!--</Border>--> <ListBox x:Name="listbox1" Height="415" ItemsSource="{Binding}" Margin="0,0,0,0" VerticalAlignment="Top" SelectionChanged="listbox1_SelectionChanged" IsSynchronizedWithCurrentItem="{x:Null}"> <ListBox.ItemTemplate> <DataTemplate> <Grid Height="30" Margin="5,0,0,2"> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth="130" Width="130" MaxWidth="150"/> <ColumnDefinition MinWidth="150" Width="150" MaxWidth="200" /> <ColumnDefinition MinWidth="150" Width="150" MaxWidth="200"/> <ColumnDefinition MinWidth="200" Width="250" MaxWidth="400" /> </Grid.ColumnDefinitions> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="0"> <TextBlock Grid.Column="0" Text="{Binding KHMC}"></TextBlock> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="1"> <HyperlinkButton Grid.Column="1" HorizontalContentAlignment="Left" Tag="{Binding KHMC}" Content="{Binding GDDH}" Click="HyperlinkButton_Click_CALLGDDH"></HyperlinkButton> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="2"> <HyperlinkButton Grid.Column="2" HorizontalContentAlignment="Left" Tag="{Binding KHMC}" Content="{Binding YDDH}" Click="HyperlinkButton_Click_CALLYDDH"></HyperlinkButton> </Border> <Border BorderBrush="Gray" BorderThickness="1" Grid.Column="3"> <TextBlock Grid.Column="3" Text="{Binding DZ}"></TextBlock> </Border> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </ScrollViewer> <!--数据列表结束--></pre> <span style="background-color:#fcfcfc;font-family:sans-serif,Verdana,arial,微软雅黑,宋体,SimSun;color:#333333;">绑定数据列表:<pre class="brush:c#; toolbar: true; auto-links: false;">List<KHModel> lt = new List<KHModel>(); var khlist = from userdata in xele.Descendants("ROW") select userdata; foreach (var khitem in khlist) { KHModel kh = new KHModel(); kh.KHBH = khitem.Element("KHBH").Value; kh.SSGSBH = khitem.Element("SSGSBH").Value; kh.KHMC = khitem.Element("XM").Value; kh.GDDH = khitem.Element("GDDH").Value; kh.YDDH = khitem.Element("YDDH").Value; kh.DZ = khitem.Element("DZ").Value; lt.Add(kh); } listbox1.ItemsSource = lt; //实体类 public class KHModel { public string KHBH { get; set; } public string SSGSBH { get; set; } public string KHMC { get; set; } public string GDDH { get; set; } public string YDDH { get; set; } public string DZ { get; set; } }</pre></span>