Windows phone 7 添加新项时,与扩展视图绑定的集合不会更新

Windows phone 7 添加新项时,与扩展视图绑定的集合不会更新,windows-phone-7,binding,sqlmetal,Windows Phone 7,Binding,Sqlmetal,我在主页中使用了一个扩展视图,该视图绑定到帐户类别集合。此集合中的每个项目都有一个帐户集合 这些绑定都工作正常,但有一个小故障。还有另一个页面,用户可以在其中添加新帐户,从而更改帐户和帐户类别。现在,当我导航回主页时,Expander控件不显示更新的值 绑定在主页的OnNavigatedTo事件上完成 数据库上下文文件由Sql Metal工具生成 更多关于这个 这意味着我的所有类都实现INotifyChanging&INotifyChangedEvents 下面是XAML&C代码 private

我在主页中使用了一个扩展视图,该视图绑定到帐户类别集合。此集合中的每个项目都有一个帐户集合

这些绑定都工作正常,但有一个小故障。还有另一个页面,用户可以在其中添加新帐户,从而更改帐户和帐户类别。现在,当我导航回主页时,Expander控件不显示更新的值

绑定在主页的OnNavigatedTo事件上完成 数据库上下文文件由Sql Metal工具生成 更多关于这个

这意味着我的所有类都实现INotifyChanging&INotifyChangedEvents

下面是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>
有什么问题吗?
提前感谢您的帮助。

主页面将从OnNavigatedTo方法中的上下文重新加载数据


确保将更新后的数据保存/标记到“添加新帐户”页面的上下文中。

确保将更新后的数据保存/标记到“添加新帐户”页面的上下文中。我正在将数据保存到“添加新帐户”页面。但是当我回到主页时,新输入的记录就不可见了..伙计们,有人请帮忙。。现在我有点不知所措了感谢我之前的评论:向我们展示在AddNewAccount页面中保存数据的代码。