0

我为 WP7 开发了一个应用程序,自定义列表框的创建和使用是通过一个新类实现的。

一旦在 CustomListBox.xaml 中声明了 Textbox 等元素,就可以在 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)
            {

            }



        }

以下是列表框的实现 MainPage.xaml

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

            </ListBox>

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

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

谢谢。

4

1 回答 1

0

Windows 应用商店/Metro 应用与 WP7 具有相同的 UI 组装核心概念。您可以创建用户控件或自定义控件,这两者都可以在您的页面的 XAML 中重复使用。

基本上,你做错了什么!您必须提供更多详细信息才能获得正确的答案!

于 2012-10-01T07:40:23.770 回答