0

更新操作が必要な Windows Phone 7 アプリケーションを開発しています。次のテーブル クラスがあります。

[Table]
public class StudentTable
{

    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int StudentID
    {
        get;
        set;
    }

    [Column (CanBeNull = false)]
    public string StudentName
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public string StudentClass
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public DateTime regDate
    {
        get;
        set;
    }
}

次の方法で各生徒の値を取得しています..

 using (StudentDataContext context = new StudentDataContext(strConnectionString))
        {

            StudentTable newStudent = new StudentTable
            {

                StudentName = textBox1.Text.ToString(),
                StudentClass = textBox2.Text.ToString(), 
                regDate = ((DateTime) datePicker.Value).Date.Add(((DateTime)timePicker.Value).TimeOfDay) 

            };

            context.StudentInfo.InsertOnSubmit(newStudent);
            context.SubmitChanges();

        }

学生をリストボックスに表示します....

                 <ListBox HorizontalAlignment="Left"  Name="StudentlistBox1" ItemsSource="{Binding}"  Loaded="StudentlistBox1_Loaded">
                 <ListBox.ItemTemplate>
                     <DataTemplate>
                         <StackPanel>
                               <TextBlock Text="{Binding StudentName}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
                               <TextBlock Text="{Binding StudentClass}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
                               <TextBlock Text="{Binding regDate}" FontSize="{StaticResource PhoneFontSizeSmall}"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

リストボックスで選択した各項目が、選択したレコードを更新できるページにつながるようにコーディングしようとしています。選択したアイテムの主キーを取得できれば、それができると思います...リストボックスで学生を選択し、その学生IDを渡すにはどうすればよいですか? どんなアイデアでも.....Windows Phone 7が初めてです..助けてください..

4

1 に答える 1

0

方法 1 :- ナビゲーション経由で詳細を渡す

String uri = "/Page2.xaml?param1="+value;
NavigationService.Navigate(new Uri(uri, UriKind.Relative));

そして、メソッドに移動したときにページ2にアクセスします:-

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

このような:-QueryString this.NavigationContext.QueryString["param"];

方法 2:- ID を IsolatedStorage 設定に保存する

private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings["paramFromPage1"]=paramValue;

そして、appSettings["paramFromPage1"] を使用して取得し、ページ 2 で適切に解析します。

*方法 3:- [アプリケーションの LifeTimeObjects にある可能性があります!!]

于 2013-01-24T16:30:49.913 に答える