gpt4 book ai didi

silverlight - 如何获取 datasourcechanged 事件?列表框

转载 作者:行者123 更新时间:2023-12-04 17:57:42 25 4
gpt4 key购买 nike

如何在列表框中获取 itemsourcechangedevent?

例如。 itemsource 从 null 更改为 ListA,然后更改为 ListB

我知道没有这样的事件。但是有什么解决方法吗?

提前致谢 :)

最佳答案

一种常用(已回答)的方法是使用 PropertyChangedTrigger来自混合 SDK。但是我不喜欢推荐使用其他 SDK,除非有明确的指示 SDK 已经在使用中。

我暂时假设您想在代码隐藏中监听“ItemsSourceChanged”事件。您可以使用的一种技术是创建一个 DependencyProperty在您的 UserControl并将其绑定(bind)到您要收听的控件的 ItemsSource。

private static readonly DependencyProperty ItemsSourceWatcherProperty = 
DependencyProperty.Register(
"ItemsSourceWatcher",
typeof(object),
typeof(YourPageClass),
new PropertyMetadata(null, OnItemsSourceWatcherPropertyChanged));

private static void OnItemsSourceWatcherPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
YourPageClass source = d As YourPageClass;
if (source != null)
source.OnItemsSourceWatcherPropertyChanged();
}

private void OnItemsSourceWatcherPropertyChanged()
{
// Your code here.
}

现在鉴于您的 ListBox有一个名称“myListBox”,您可以设置观看:-
Binding b = new Binding("ItemsSource") { Source = myListBox };
SetBinding(ItemsSourceWatcherProperty, b);

关于silverlight - 如何获取 datasourcechanged 事件?列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5119417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com