1

我有一个简单的客户地址表格。国家和州组合框链接到 ListCollectionViews。因此,当用户更改国家/地区设置时,可以在模型视图中过滤状态列表。问题是当表单加载一些以前的信息时,状态组合框即使有数据也是空白的。似乎是因为它们放在 xaml 中的顺序。如果我把国家组合框放在国家之前,如果工作正常,但我希望国家在国家之后。有没有办法让 xaml 布局保持原样,但在状态之前处理国家组合框?

xml:

<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>

ViewModel 过滤器:

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;
    };
}
4

1 回答 1

2

依赖于正在处理的 xaml 的顺序会很糟糕。

当应该更新 ComboBox 并将 View 绑定到 ViewModel 上的一个额外属性时,尝试在 ViewModel 中找到合适的事件。

于 2011-08-04T08:34:57.140 回答