0

Windows phone 用のアプリを開発していますが、最近リスト ボックスに問題がありました。これはエミュレーターでは正常に動作しますが、デバイスに展開すると何も表示されません。リスト項目は要求どおりに作成されますが、各項目をクリックしたときに情報が含まれていないため、バインディングは実行されません。それに関連するコードは次のとおりです

XAML

<ListBox Name="NotesListBox" Grid.Row="0" Margin="15,0" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>                
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <local:NotesTile Name="TileNotes" Tap="NotesTile_Tap_1" Margin="10,10"/>
                        <TextBlock Text="{Binding FileName}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

C# コード ビハインド

 List<Notes> source = new List<Notes>()
            {
                new Notes(){ Content="This is some text", FileName="one.txt", IsPasswordProtected=true},
                new Notes(){ Content="Another text file", FileName="two.txt", IsPasswordProtected=false}
            };


            //this.DataContext = this;
            this.NotesListBox.ItemsSource = source;

同じ名前空間で、クラスを次のように取得しました:

class Notes
{
    public string Content { get; set; }
    public string DateEdited { get; set; }
    public string TimeEdited { get; set; }
    public string FileName { get; set; }
    public bool IsPasswordProtected { get; set; }
}

エミュレーターや、Windows Phone 8 用に作られたデバイスでも問題なく動作しました。同じ理由で、アプリがマーケットプレイスで拒否されました。

編集

Binding クラスは常に public である必要があります。クラス Notes を public にすると、この問題は解決します。

4

1 に答える 1

0

InitilizeComponent() の前に xaml.cs のコンストラクターで設定this.DataContext = this;してみて、うまくいくかどうかお知らせください。

于 2013-03-22T06:44:18.180 に答える