2012-01-31 12 views
0

私のメインページには「アカウントカテゴリ」のコレクションにバインドされたエクスパンダビューが使用されています(このコレクションの各アイテムにはさらにアカウントがあります)コレクション新しいアイテムが追加されたときに拡大表示にバインドされたビューは更新されません

バインディングはすべてうまく動作していますが、小さな欠点もあります。ユーザーが新しいアカウントを追加できる別のページがあります(したがって、アカウントの変更&アカウントカテゴリ)。メインページに戻ると、エクスパンダコントロールに更新された値が表示されません。

バインディングがデータベースコンテキストファイルはすべて私のクラスは、& INotifyChangedEvents

をINotifyChanging実装を意味するSQL金属工具 (ここでは、この Using SQl Metal to generate DB files for wp7の詳細)

によって生成されるメインページ のOnNavigatedToイベントで行われますここ

はXAML & C#コードであり、ここで

private WalletDataContext context; 

    private ObservableCollection<AccountCategory> _accountCategories; 
    public ObservableCollection<AccountCategory> AccountCategories 
    { 
     get { return _accountCategories; } 
     set 
     { 
      if (_accountCategories != value) 
      { 
       _accountCategories = value; 
       NotifyPropertyChanged("AccountCategories"); 
      } 
     } 
    } 

public MainPage() 
    { 
     InitializeComponent(); 

     //Initialize Data context 
     context = new WalletDataContext(WalletDataContext.DBConnectionString); 

     //Set page data context 
     this.DataContext = this; 
    } 

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     //fetch all existing Account Categories 
     var accountCategoriesInDB = (from AccountCategory acctCat in context.AccountCategory 
            select acctCat); 

     //Update Page Collection 
     AccountCategories = new ObservableCollection<AccountCategory>(accountCategoriesInDB); 

     this.listBox.ItemsSource = AccountCategories; 

     base.OnNavigatedTo(e); 

    } 

はXAMLでありますバインディング

<ListBox Grid.Row="0" x:Name="listBox"> 
        <ListBox.ItemContainerStyle> 
         <Style TargetType="ListBoxItem"> 
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
         </Style> 
        </ListBox.ItemContainerStyle> 

        <ListBox.ItemsPanel> 
         <ItemsPanelTemplate> 
          <StackPanel/> 
         </ItemsPanelTemplate> 
        </ListBox.ItemsPanel> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <toolkit:ExpanderView Header="{Binding}" Expander="{Binding}" 
          ItemsSource="{Binding Accounts}" 
          HeaderTemplate="{StaticResource CustomHeaderTemplate}" ExpanderTemplate="{StaticResource CustomExpanderTemplate}"> 
           <toolkit:ExpanderView.ItemTemplate> 
            <DataTemplate> 
             <Grid VerticalAlignment="Center" Height="Auto"> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="0.105*"/> 
               <RowDefinition Height="0.105*"/> 
               <RowDefinition Height="0.789*"/> 
              </Grid.RowDefinitions> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="0.366*"/> 
               <ColumnDefinition Width="0.634*"/> 
              </Grid.ColumnDefinitions> 

              <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding AccountNumber}" Style="{StaticResource PhoneTextNormalStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock> 
              <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Balance}" Style="{StaticResource PhoneTextSubtleStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock> 
             </Grid> 
            </DataTemplate> 
           </toolkit:ExpanderView.ItemTemplate> 
          </toolkit:ExpanderView> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 

何が問題なのですか? 事前に助けてくれてありがとう。

答えて

0

メインページは、OnNavigatedToメソッドのコンテキストからデータをリロードします。

更新されたデータを[新しいアカウントの追加]ページのコンテキストに保存/マークしてください。

+0

"新しいアカウントの追加ページでデータを保存しています。"新しいアカウントの追加ページで、更新されたデータをコンテキストに保存/マークしてください。しかし、メインページに戻ると、新しく入力されたレコードは表示されません。 – Supreet

+0

データを保存するコードを表示できますか? –

+0

あなたのお手伝いをしてくれる人はいらっしゃいますか?:(ありがとう – Supreet

関連する問題