0

私はWindowsPhone7のプログラミングは初めてですが、1つの問題に3日間費やすと本当に疲れます。私はすべてのインターネットを検索し、いくつかの良い説明を取得しますが、運がなければ-それは私のプログラムでは機能しません。

SQL Azureで、dbo.Messengerと呼ばれる構造を持つ1つのテーブルを作成します。

  • id(PK、nullではない)
  • カテゴリ(nvarchar(30)、null)
  • メッセージ(nvarchar(max)、null)
  • 説明(nvarchar(200)、null)

それから私はそれのために作りますWCFwchichは私にそれのリストを持ってくるべきです:

      [OperationContract]
        List<NoteDto> GetNotes();
    public List<NoteDto> GetNotes()
    {
        using (var context = new WP7mgrEntities())
        {
            var notes = (from eachNote in context.Messenger
                         orderby eachNote.id ascending
                         select new NoteDto
           {
               id = eachNote.id,
               category= eachNote.category,
               description= eachNote.description,
               message= eachNote.message,
           }
                ).ToList();
            return notes;
        }
    }

追加のクラスNoteDtoで、このように各DataMemberに対して取得したコースの数:

  [DataMember] 
    public int id {get; set; }

したがって、この後、ボタン2をクリックしてリストボックスを取得するwp7アプリを作成します。

        <ListBox Height="431" HorizontalAlignment="Left" Margin="12,199,0,0" Name="listBox1" VerticalAlignment="Top" Width="438"
                 ItemsSource="{Binding Notes}">
         <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding category}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>         
        </ListBox> 

そして、この背後にあるこのコード:

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        Service1Client client = new Service1Client();
        client.GetNotesCompleted += new EventHandler<GetNotesCompletedEventArgs>(client_GetNotesCompleted);
        this.Notes = new ObservableCollection<NoteDto>();

    }
    private ObservableCollection<NoteDto> _notes;
    public ObservableCollection<NoteDto> Notes
    {
        get { return _notes; }
        set { _notes = value;
        this.RaisePropertyChanged("Notes");
        } 
    }

パブリックイベントPropertyChangedEventHandlerPropertyChanged; private void RaisePropertyChanged(string propertyName){PropertyChangedEventHandler propertyChanged = this.PropertyChanged; if((propertyChanged!= null)){propertyChanged(this、new PropertyChangedEventArgs(propertyName)); }}

    void client_GetNotesCompleted(object sender, GetNotesCompletedEventArgs e)
    {this.Notes = e.Result; }

ボタン2をクリックすると、リストボックスにデータベースのレコードが表示されません。
何か案が ?Plzヘルプ?

4

1 に答える 1

0

どんなバインディングを使っていますか?WP7ではwshttpbindingのみが使用できないことを思い出してください。一方、ODataなどのWCFDataServiceを使用してこのようなデータベースを公開してみませんか。

見てみな。

お役に立てば幸いです。

于 2012-04-05T20:37:57.747 に答える