1
我有一個簡單的客戶地址表單。國家和州組合框鏈接到ListCollectionViews。當用戶更改國家/地區設置時,狀態列表可以在模型視圖中過濾。問題是,當表單載入一些以前的信息時,狀態組合框即使通過數據也是空白的。這似乎是因爲它們放置在xaml中的順序。如果我把國家的組合框放在國家之前,如果工作正常,但是我希望國家能夠在國家之後來。有沒有辦法讓xaml佈局保持原樣,但是在國家之前處理國家組合框?WPF 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;
};
}
嗨@Erno,我試圖在過濾器運行後使用RaisePropertyChanged,但它沒有做任何事情。似乎它只是需要重新評估其綁定。 – chinupson
@chinupson,我真的認爲你必須在你的viewmodel中解決它,但暫時你可以看看:http://social.msdn.microsoft.com/forums/en-US/wpf/thread/2ee69a80-c3ae-486b-a3d3-9f207c7e93f4 –
@chinupson,另外:http://stackoverflow.com/questions/656552/is-it-possible-to-refresh-wpf-data-bindings –