我開發了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>
方式
我想知道在地鐵應用程序中是否可以遵循相同的程序?
我嘗試使用相同的方法進行自定義,但失敗。我應該採用不同的方法嗎?
謝謝。
請在這裏發佈一些代碼示例,所以我可以幫助你! – gyurisc
@gyurisc添加代碼,提前致謝。 – indiaxxo