0

基本的に私はこのシンプルなメモアプリを作っていて、リストボックスを持っています。ユーザーが保存ボタンをクリックしてメモを追加すると、メモは .txt ファイルとして保存され、リストボックスにメモが表示されます。したがって、ユーザーが変更などを行いたい場合は、保存したメモの名前になるリストボックス項目をクリックするだけです。私がやりたいことは、基本的にユーザーが保存をクリックすると保存され、リストボックスにメモの名前が表示されるので、たとえばメモ名がtest.txtの場合、リストボックスにtest.txtが表示されます。リストボックスに表示されるアイテム名のすぐ下に、サブアイテムのようなものを追加するにはどうすればよいですか? たとえば、wp7 のメールのように。メールの件名と、最初の 12 程度の単語を示すサブアイテムがあります。アプリでこれを行うにはどうすればよいですか? これまでのところ、音名しかわかりませんでした。名前とメッセージの最初の 14 語をアイテムの下に表示したい。

私のコードはこれまでのところ:

これにより、基本的に myNote フォルダー内のアイテムがリストボックスに追加され、保存されたメモが表示されます。

Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    myIsolatedStorage.CreateDirectory("myNote")
    Dim directory As String = "./myNote/*.*"
    Dim filenames As String() = myIsolatedStorage.GetFileNames(directory)
    ListBox1.ItemsSource = filenames

これはリストボックスのxmlです

<ListBox HorizontalAlignment="Left" Margin="8,8,0,8" x:Name="ListBox1" Width="440" SelectionMode="Single" FontSize="32" FontFamily="Segoe WP SemiLight" RenderTransformOrigin="0.5,0.5" Grid.Row="2" Style="{StaticResource ListBoxStyle1}" Foreground="White" BorderBrush="#00000000" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" ItemsPanel="{StaticResource ItemsPanelTemplate1}" />

誰?ありがとう!

4

1 に答える 1

0

各リストボックス項目のファイル タイトルの下にテキストを追加するには、ListBoxの新しいItemTemplateを定義する必要があります。独自のItemTemplateを定義することで、各リストボックス アイテムの表示方法を正確に選択できます。

提供されている の小さなサンプルを次に示しますListbox。テンプレート (DataTemplateセクションに含まれるすべてのもの) は非常にシンプルです。色やフォントなどを変更してカスタマイズするのはあなた次第です...

あなたのxamlページで:

        <ListBox HorizontalAlignment="Left" Margin="8,8,0,8" x:Name="ListBox1"
                 Width="440" SelectionMode="Single"
                 FontSize="32" FontFamily="Segoe WP SemiLight"
                 RenderTransformOrigin="0.5,0.5" Grid.Row="2"
                 Style="{StaticResource ListBoxStyle1}"
                 Foreground="White" BorderBrush="#00000000"
                 ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
                 ItemsPanel="{StaticResource ItemsPanelTemplate1}" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="{Binding FileName}" FontWeight="Bold"></TextBlock>
                        <TextBlock Text="{Binding Content}"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

次にItemsSource、新しいタイプのList. ファイル名List(Listの) を割り当てるだけでなく、次のような のStringを指定する必要があります。List

Public Class NewListItem
    Public Property FileName() As String
        Get
            Return m_FileName
        End Get
        Set
            m_FileName = Value
        End Set
    End Property
    Private m_FileName As String
    Public Property Content() As String
        Get
            Return m_Content
        End Get
        Set
            m_Content = Value
        End Set
    End Property
    Private m_Content As String
End Class

FileNameつまり、基本的には、 と の 2 つのプロパティを含む単なるデータ構造Contentです。

List最後に、ファイル名を反復処理し、新しいプロパティに適切な値を入力して、新しいタイプの を構築する必要がありListます (もちろん、これは単なる疑似コードです)。

Dim newList As New List(Of NewListItem)()
For Each file As var In filenames
    Dim item As New NewFileItem()
    item = file
    ' open the file the way you want
    ' extract the 14 first characters the way you want
    Dim content As String = InlineAssignHelper(item.Content, content)
    newList.Add(item)
Next
ListBox1.ItemsSource = filenames
于 2013-10-20T13:37:13.997 に答える