顧客用の簡単な住所フォームがあります。国と州のコンボ ボックスは、ListCollectionViews にリンクされています。これは、ユーザーが国の設定を変更したときに、州のリストをモデル ビューでフィルター処理できるようにするためです。問題は、フォームが以前の情報を読み込むときに、状態コンボ ボックスがデータを持っていても空白になることです。xamlに配置されている順序が原因のようです。国コンボボックスを州の前に置くとうまくいきますが、州の後に国を置きたいと思います。xaml レイアウトをそのままにしておく方法はありますが、状態の前に国のコンボ ボックスを処理することはできますか?
Xaml:
<StackPanel Orientation="Horizontal">
<TextBlock Height="23" Name="tbkMailState" Text="State/Province:" Width="80" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2" Foreground="Black" />
<ComboBox Height="23" Name="cmbMailState" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2" Foreground="Black" ItemsSource="{Binding GeoStateListMail}" SelectedValue="{Binding OpenEntityListing.EntityMailAddress.GeoState_Id}" DisplayMemberPath="Name" SelectedValuePath="Id" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Height="23" Name="tbkMailCountry" Text="Country:" Width="80" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2" Foreground="Black" />
<ComboBox Height="23" Name="cmbMailCountry" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2" Foreground="Black" ItemsSource="{Binding GeoCountryListMail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValue="{Binding OpenEntityListing.EntityMailAddress.GeoCountry_Id}" DisplayMemberPath="Name" SelectedValuePath="Id" IsSynchronizedWithCurrentItem="True" />
</StackPanel>
ビューモデル フィルター:
public void GeoCountry_CurrentChanged(object sender, EventArgs e)
{
GeoStateList.Filter = item =>
{
GeoState vitem = item as GeoState;
if ((OpenEntityListing == null) || (vitem == null))
{
return false;
}
return vitem.GeoCountry_Id == OpenEntityListing.EntityAddress.GeoCountry_Id;
};
}