私はWP7用のアプリを開発しました。カスタムリストボックスの作成と使用は、新しいクラスを介して行われます。
Textbox などの要素が 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)
{
}
}
以下は、リストボックスの実装 MainPage.xaml になります。
<ListBox x:Name="MyListBox" SelectionMode="Single" Margin="-4,6,-12,12" SelectionChanged="MyListBox_SelectionChanged">
</ListBox>
メトロ アプリで同じ手順を実行できるかどうかを知りたいですか?
同じ方法でカスタマイズしようとしましたが、失敗しました。別のアプローチに従うべきですか?
ありがとう。