0
votes

I'm new in programming windows phone 7 but get really tired cuz i spend 3 days on one problem. I search all internet and get some good explanions but without luck - it doesn't work on me program.

I create in SQL Azure one table which i called dbo.Messenger with structure:

  • id (PK, not null)
  • category (nvarchar(30), null)
  • message (nvarchar(max), null)
  • description (nvarchar(200), null)

Then i make for it WCF wchich should bring me a list of it:

      [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;
        }
    }

of cource got for each DataMember like this on extra class NoteDto:

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

So after this i make wp7 apps which get listbox which should also be fill afert i click button2

        <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> 

And this code behind of this:

    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");
        } 
    }

public event PropertyChangedEventHandler PropertyChanged; 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; }

When i click button 2 my listbox isn't fill by records from database.
Any idea ? Plz help ?

1
You don't really know whether your code is failing to get the notes or whether the screen is failing to respond to the change. I'd change button2_Click to just set this.Notes to a static value.Rich
I'm saying just something like within button2_Click: this.Notes = new List<NoteDto>{ new NoteDto { id = 1, category = "Foo" }}; Debugging 101..figure out which part is failing. Then figure out why.Rich

1 Answers

0
votes

What kind of binding are you using? recall that only wshttpbinding is not available for WP7. On the other hand, why don't you expose such database with WCF Data Service as OData.

Check it out.

Hope it helpful,