メインページで「アカウントカテゴリ」のコレクションにバインドされているエキスパンダービューを使用しています(このコレクションの各アイテムには、さらにアカウントのコレクションがあります)
バインディングはすべて正常に機能していますが、小さな不具合があります。メインページに戻ると、ユーザーが新しいアカウントを追加できる(つまり、アカウントとアカウントカテゴリを変更する)別のページがあります。エキスパンダーコントロールに更新された値が表示されませんか?
バインディングはメインページのOnNavigatedToイベントで行われます。データベースコンテキストファイルはSQLMetalツールによって生成されます(これについて詳しくは、SQl Metalを使用してwp7のDBファイルを生成します) 。
つまり、すべてのクラスが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>
何が悪いのかについてのアイデアはありますか?よろしくお願いします。