私はWindows 7の電話機では新しいですが、1つの問題で3日間を費やしています。私はすべてのインターネットを検索し、良い説明を得るが、運がない - それは私のプログラムではうまくいかない。 (nullのデータ型はnvarchar(30)、)WCFを使用してWindows Phone 7にSQL Azureを接続
- ID
- カテゴリ(、nullでないPK)
- :私は構造でdbo.Messengerと呼ばれるSQL Azureの一つのテーブルに作成
メッセージ(nullのデータ型はnvarchar(200)、()はnullデータ型はnvarchar(MAX)、)
- 説明
が、私はWCそれのために作りますFはwchich私にそれのリストを持参してください:讲义1コースの
[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]
public int id {get; set; }
ので、この後、私はWP7を作りますリストボックスを取得するアプリケーションも、ボタンをクリックすると表示されます。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>
そして、これの背後に、このコード:
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");
}
}
公開イベントPropertyChangedEventHandlerのPropertyChanged; プライベートvoid RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler propertyChanged = this.PropertyChanged; if((propertyChanged!= null)) { propertyChanged(this、新しいPropertyChangedEventArgs(propertyName));私は、データベースからレコードで埋めるされていないボタン2私のリストボックスをクリックし }}
void client_GetNotesCompleted(object sender, GetNotesCompletedEventArgs e)
{this.Notes = e.Result; }
。
Plzは助けますか?
、それが参考に願っています。私はちょうどthis.Notesを静的な値に設定するためにbutton2_Clickを変更します。 – Rich
これを設定するには? – HelpMyProgram
私はbutton2_Clickのようなものを言っています:this.Notes = new List {new NoteDto {id = 1、category = "Foo"}};デバッグ101.どの部分が故障しているかを示します。それでは理由を見つけてください。 –
Rich