C# ListBox中的ComboBox触发SelectionChanged事件,但ComboBox中选定项的值未得到更新-MVVM模式
我有一个UWP应用程序,使用Prism framework\toolkit。该应用程序有一个列表视图。每行由各种文本块和一个组合框组成。最初,当网格加载时,我希望ComboBox不显示选中的项目,而是显示加载的项目源。用户现在必须从组合框中选择任何项目。列表框和组合框是从ViewModel中的两个不同的ObservableCollection填充的。对于列表框中的组合框,SelectionChanged事件确实会为我触发,因为我正在使用Dependency属性,但是用户从组合框中选择的项目,所选值的正确值不会在视图模型中更新。 我有一个列表视图,其中包含ComboBox 我已从下面的应用程序中添加了代码段: 我在这里也使用行为SDKC# ListBox中的ComboBox触发SelectionChanged事件,但ComboBox中选定项的值未得到更新-MVVM模式,c#,mvvm,combobox,win-universal-app,C#,Mvvm,Combobox,Win Universal App,我有一个UWP应用程序,使用Prism framework\toolkit。该应用程序有一个列表视图。每行由各种文本块和一个组合框组成。最初,当网格加载时,我希望ComboBox不显示选中的项目,而是显示加载的项目源。用户现在必须从组合框中选择任何项目。列表框和组合框是从ViewModel中的两个不同的ObservableCollection填充的。对于列表框中的组合框,SelectionChanged事件确实会为我触发,因为我正在使用Dependency属性,但是用户从组合框中选择的项目,所选
<ListView x:Name="AssignCountryStateGridData" Grid.Row="1"
HorizontalAlignment="Left" ItemsSource="{Binding AssignCCPGridInfo,Mode=TwoWay}" MinWidth="805" MinHeight="480">
<ListView.ItemTemplate>
<DataTemplate>
<Grid MinHeight="25" MinWidth="805">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions >
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<TextBlock FontSize="13" Foreground="White" Grid.Column="0" Text="{Binding CompanyCode}" ToolTipService.ToolTip="{Binding CompanyCode}" TextAlignment="Center"/>
<TextBlock FontSize="13" Foreground="White" Grid.Column="1" Text="{Binding CustomerNbr}" ToolTipService.ToolTip="{Binding CustomerNumber}" TextAlignment="Center"/>
<ComboBox Grid.Column="3" Height="25" Width="20" Margin="20,5,0,0" VerticalAlignment="Center" x:Name="comboBoxCountryCode"
ItemsSource="{Binding Path=DataContext.EFSSAPCountryCode,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="CountryCode"
SelectedValue="{Binding SelectedCountryCode,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding ElementName=AssignCountryStateGridData,Path=DataContext.LoadSelectedCountryCodeCommand}"
CommandParameter="{Binding SelectedValue,ElementName= AssignCountryStateGridData}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ComboBox>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我不确定这段代码出了什么问题。在集合中,您没有调用NotifyPropertyChanged?我继承了从INotifyPropertyChanged继承的BindableBase抽象类。在这里,我粘贴了其中的一小部分。notify属性对于my中的所有其他100个控件都正常工作application@Stamos-那没用-命令触发了吗?你试过设置断点吗?是的…命令被触发了。我的断点被击中了。但我的属性SelectedCountryCode未设置。
private ObservableCollection<EFSSAPCountryCode> _EFSSAPCountryCode;
private EFSSAPCountryCode _SelectedCountryCode;
public DelegateCommand LoadSelectedCountryCodeCommand { get; set; }
[RestorableState]
public ObservableCollection<EFSSAPCountryCode> EFSSAPCountryCode
{
get { return _EFSSAPCountryCode; }
set { SetProperty(ref _EFSSAPCountryCode, value); }
}
[RestorableState]
public EFSSAPCountryCode SelectedCountryCode
{
get { return _SelectedCountryCode; }
set { SetProperty(ref _SelectedCountryCode, value); }
}
public AssignCountryStateProvinceCodesViewModel()
{
this.LoadSelectedCountryCodeCommand = DelegateCommand.FromAsyncHandler(GetColumnsForSelectedCountryCode);
}
public async override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> viewModelState)
{
//Set EFSSAPCountryCode and other call for service
}
private async Task GetColumnsForSelectedCountryCode()
{
//I am getting call here when I select something from Combo Box but I never get what was selected by the user from the Combo Box and "SelectedCountryCode" stays null
}
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}