2012-06-07 2 views
0

WP7에서 개체 요소에 쓰기/읽기를하는 간단한 방법을 만들고 싶습니다. 뭔가 제대로 작동하지 않습니다. 내 사고 방식과 내가 이미 한 일은 다음과 같습니다.개체에 쓰기/읽기

먼저 내 개체를 나타내는 클래스를 만듭니다. 내가 App.xaml.cs를에 약간의 변경이 필요합니다 몇 가지 기사를 읽을 때,

namespace SimpleObject.Objects 
{ 
    public class Entry 
    { 
     public string entrytitle { get; set; } 
     public string entrycomment { get; set; } 
     public string entrycat = "works"; 

     public Entry() { } 
     public Entry(string Entrytitle, string Entrycomment, string Entrycat) 
     { 

      this.entrytitle = Entrytitle; 
      this.entrycomment = Entrycomment; 
      this.entrycat = Entrycat; 
     } 

     public string entry { get; set; } 

    } 
} 

를 그리고 여기에서 우리는 간다 : 나는 모든 것이 잘 작동하면 바로 볼 정적 문자열을 추가

SimpleObject.Objects를 사용하여;

하기 전에 응용 프로그램() 나는이 넣어 :

공공 정적 항목 E를; 앱에서 다음

()이 :

UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>(Application_UnhandledException); 

E = new Entry(); 

InitializeComponent(); 

그런 다음 내 UI는 두 페이지입니다. 하나는 데이터를 입력하고 두 번째로 읽는 형식입니다. 응용 프로그램 막대 버튼에서 내가 가진 :

private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      TextBlock1.Text = App.E.entrycat; 
      TextBlock2.Text = App.E.entrytitle; 
     } 

그리고 두 번째 TextBlock이 나에게 아무것도주지 않는다 ... 당신은 결코 글로벌 정적 값을 설정하지하고

답변

0

: 현재 결과

private void ApplicationBarIconButton_Click(object sender, System.EventArgs e) 
     { 
      Entry E = new Entry 
      { 
       entrytitle = TitleTextBox.Text, 
       entry = CommentTextBox.Text, 
      }; 

      this.NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative)); 
      MessageBox.Show("Category added!"); 

     } 

마지막 페이지를. 당신의 버튼 클릭, 그것은이 있어야한다 :

private void ApplicationBarIconButton_Click(object sender, System.EventArgs e) 
{ 
    App.E.entrytitle = TitleTextBox.Text, 
    App.E.entrycat = CommentTextBox.Text, 

    this.NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative)); 
} 
+0

이 변경 이후 아무 것도 결과를 제공하지 않습니다. – dargod

+0

내가 제안 할 수있는 것은 당신이 디버거를 사용한다는 것입니다. App.E 값은 1 페이지에 설정 되나요? 버튼을 클릭 할 때 여전히 그곳에 있습니까? 다른 것이 (또는 E 자체) 값을 덮어 쓰지 않는 한, 또는 앱 논리가 게시 한 내용과 정확히 일치하지 않는 경우 작동하지 않아야합니다. – ctacke

+0

일반적으로 WP에서 데이터를 관리하는 방법을 배우고 싶습니다. 권장할만한 좋은 자습서가 있습니까? – dargod

0

또 다른 옵션은 기본적으로 하나의 페이지에서 다음에 값을 전달하는 데 사용하는 전역 변수를 포기하는 것입니다.

웹 응용 프로그램 에서처럼 쿼리 문자열 값을 사용하여이를 수행 할 수 있으며 페이지로드 핸들러에서이를 선택할 수 있습니다.

private void ApplicationBarIconButton_Click(object sender, System.EventArgs e) 
{ 
    this.NavigationService.Navigate(new Uri("/Page2.xaml?title=TitleTextBox.Text&comment=CommentTextBox.Text", UriKind.Relative)); 
}