2012-10-01 56 views
0

我开发了WP7应用程序,创建和使用自定义列表框是通过一个新类。Metro应用程序 - 自定义列表框/列表视图

一旦在CustomListBox.xaml中声明了文本框等元素,就可以在MainPage.cs中使用它。

这里去了CustomListBox.xaml

<UserControl x:Class="Sample.CustListbox" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    d:DesignHeight="150" d:DesignWidth="480"> 

    <Grid x:Name="LayoutRoot"> 
     <Grid.Background> 
      <ImageBrush Stretch="Fill" ImageSource="gradient.jpeg"/> 
     </Grid.Background> 
     <TextBlock Height="56" Margin="160,19,0,75" Name="textBlock1" Text="" Width="293" FontStyle="Normal" HorizontalAlignment="Center" 
              Foreground="Black" VerticalAlignment="Center" 
              TextAlignment="Left" FontSize="24" TextWrapping="Wrap" FontFamily="Verdana"/> 

     <Image Height="89" HorizontalAlignment="Left" Margin="12,19,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="110" /> 
     <TextBlock Height="61" Margin="160,81,0,8" Name="textBlock2" Text="" Width="293" FontStyle="Normal" HorizontalAlignment="Center" 
              Foreground="Black" VerticalAlignment="Center" 
              TextAlignment="Left" FontSize="15" TextWrapping="Wrap" FontFamily="Verdana"/> 
    </Grid> 
</UserControl> 

而且我用我的MainPage.cs是

private void readSQLCE() 
     { 
      db = new MyDataContext("isostore:/aa.sdf"); 

      //IntroductionTable 
      var IT_Q = from b in db.IT where b.IT_id < 8 select b; 
      List<IntroductionTable> l_It = IT_Q.ToList(); 

      try 
      { 
       foreach (IntroductionTable itt in l_It) 
       { 
        //Instance for list items 
        CustListbox clb = new CustListbox(); 
        blob = itt.IT_Image; 
        MemoryStream memStream = new MemoryStream(blob); 
        WriteableBitmap bimg = PictureDecoder.DecodeJpeg(memStream); 
        clb.textBlock1.Text = itt.IT_intro; 
        clb.image1.Source = bimg; 
        MyListBox.Items.Add(clb); 
        //addingcts(); 
       } 
      } 
      catch (Exception ex) 
      { 

      } 



     } 

下面是ListBox的实施MainPage.xaml中

<ListBox x:Name="MyListBox" SelectionMode="Single" Margin="-4,6,-12,12" SelectionChanged="MyListBox_SelectionChanged"> 

      </ListBox> 
方式

我想知道在地铁应用程序中是否可以遵循相同的程序?

我尝试使用相同的方法进行自定义,但失败。我应该采用不同的方法吗?

谢谢。

+0

请在这里发布一些代码示例,所以我可以帮助你! – gyurisc

+0

@gyurisc添加代码,提前致谢。 – indiaxxo

回答

0

Windows应用商店/ Metro应用程序共享与WP7组装方式相同的核心概念。您可以创建用户控件或自定义控件,这两个控件都可以在您的页面的XAML中重新使用。

基本上,你做错了什么!你必须提供更多的细节才能得到正确的答案!

+0

非常感谢回复,我检查了是否有问题。但它不是。将再次检查。 – indiaxxo

+0

我的代码被添加,请看看@ColinE – indiaxxo