WPF ObservableCollection CollectionView.CurrentChanged 未触发
我的一个 ICollectionView
有问题。 ICollectionView
的 CurrentChanged
事件未触发。
请参阅下面我的代码。
XAML:
<!-- Publication -->
<TextBlock Name="tbkPublication" Text="{x:Static abConst:Print.tbkPublicationText}" Grid.Row="0" Grid.Column="0" Margin="3" ></TextBlock>
<ComboBox Grid.Column="1" Grid.Row="0" Margin="3"
Name="cmbPublication" BorderThickness="1"
ItemsSource="{Binding Path=EnterpriseList}" DisplayMemberPath="Name"
SelectedValuePath="Value" SelectedIndex="0"
IsSynchronizedWithCurrentItem="True" />
<!-- Distribution Area Region -->
<TextBlock Name="tbkDistributionArea" Text="{x:Static abConst:Print.tbkDistributionAreaText}" Grid.Row="1" Grid.Column="0" Margin="3" ></TextBlock>
<ComboBox Grid.Column="1" Grid.Row="1" Margin="3"
Name="cmbDistributionArea" BorderThickness="1"
ItemsSource="{Binding Path=ZonesList}"
DisplayMemberPath="Name"
SelectedValuePath="Value" SelectedIndex="0"
IsSynchronizedWithCurrentItem="True" />
和 C# (ViewModel)
#region Properties
public ObservableCollection<GenericNameValuePair<int, string>> EnterpriseList
{
get { return _abEnterpriseList; }
set { _abEnterpriseList = value; }
}
public ObservableCollection<GenericNameValuePair<int, string>> ZonesList
{
get { return _abZonesList; }
set
{
_abZonesList = value;
}
}
#endregion
private void InitCollections()
{
_collectionViewEnterprise = CollectionViewSource.GetDefaultView(EnterpriseList);
_collectionViewZone = CollectionViewSource.GetDefaultView(ZonesList);
//Replace
if(_collectionViewEnterprise == null)
throw new NullReferenceException("Enterprise collectionView is null.");
if (_collectionViewZone == null)
throw new NullReferenceException("Zone collectionView is null.");
_collectionViewEnterprise.CurrentChanged += new EventHandler(OnCollectionViewEnterpriseCurrentChanged);
_collectionViewZone.CurrentChanged += new EventHandler(OnCollectionViewZoneCurrentChanged);
}
请帮忙。提前致谢。
I have a problem with one of my ICollectionView
s. The ICollectionView
's CurrentChanged
event is not firing.
Please see my code below.
XAML:
<!-- Publication -->
<TextBlock Name="tbkPublication" Text="{x:Static abConst:Print.tbkPublicationText}" Grid.Row="0" Grid.Column="0" Margin="3" ></TextBlock>
<ComboBox Grid.Column="1" Grid.Row="0" Margin="3"
Name="cmbPublication" BorderThickness="1"
ItemsSource="{Binding Path=EnterpriseList}" DisplayMemberPath="Name"
SelectedValuePath="Value" SelectedIndex="0"
IsSynchronizedWithCurrentItem="True" />
<!-- Distribution Area Region -->
<TextBlock Name="tbkDistributionArea" Text="{x:Static abConst:Print.tbkDistributionAreaText}" Grid.Row="1" Grid.Column="0" Margin="3" ></TextBlock>
<ComboBox Grid.Column="1" Grid.Row="1" Margin="3"
Name="cmbDistributionArea" BorderThickness="1"
ItemsSource="{Binding Path=ZonesList}"
DisplayMemberPath="Name"
SelectedValuePath="Value" SelectedIndex="0"
IsSynchronizedWithCurrentItem="True" />
AND C# (ViewModel)
#region Properties
public ObservableCollection<GenericNameValuePair<int, string>> EnterpriseList
{
get { return _abEnterpriseList; }
set { _abEnterpriseList = value; }
}
public ObservableCollection<GenericNameValuePair<int, string>> ZonesList
{
get { return _abZonesList; }
set
{
_abZonesList = value;
}
}
#endregion
private void InitCollections()
{
_collectionViewEnterprise = CollectionViewSource.GetDefaultView(EnterpriseList);
_collectionViewZone = CollectionViewSource.GetDefaultView(ZonesList);
//Replace
if(_collectionViewEnterprise == null)
throw new NullReferenceException("Enterprise collectionView is null.");
if (_collectionViewZone == null)
throw new NullReferenceException("Zone collectionView is null.");
_collectionViewEnterprise.CurrentChanged += new EventHandler(OnCollectionViewEnterpriseCurrentChanged);
_collectionViewZone.CurrentChanged += new EventHandler(OnCollectionViewZoneCurrentChanged);
}
Please help. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将组合框数据绑定到集合视图而不是底层集合。下面是一个工作示例:
XAML:
代码隐藏:
You need to databind the combobox to the collectionview and not the underlying collection. Below is a working sample:
XAML:
Code behind: