sourceupdated事件不触发 [英] sourceupdated event not firing

查看:268
本文介绍了sourceupdated事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有DiscoveredHosts这是一个的ObservableCollection<字符串> 。所述sourceupdated事件不被调用。任何人都知道为什么吗?

 <组合框名称=DiscoveredHostsComboBoxVerticalAlignment =中心Grid.Column =0
    的Horizo​​ntalAlignment =中心=了minWidth100像素的ItemsSource ={绑定路径=
    DiscoveredHosts}SourceUpdated =DiscoveredHostsComboBox_SourceUpdated/>

公共无效GetDomainHosts()
{
    DiscoveredHosts.Clear();

    变种适配器= NetworkInterface.GetAllNetworkInterfaces();

    如果(Config.Debug)
    {
        DiscoveredHosts.Add(192.168.73.11);
        DiscoveredHosts.Add(192.168.73.14);
    }

    的foreach(VAR物业adapters.Select(适配器=> adapter.GetIPProperties()))
    {
        如果(properties.DnsSuffix =&放大器;!&安培;!DiscoveredHosts.Contains(
properties.DnsSuffix))
            DiscoveredHosts.Add(properties.DnsSuffix);

        如果(properties.DnsAddresses.Count< = 0)继续;

        的foreach(在properties.DnsAddresses.Where VAR主机(主机=>!DiscoveredHosts。
任何(一个= gt;一种== host.ToString())))
            DiscoveredHosts.Add(host.ToString());
    }

    OnPropertyChanged(DiscoveredHosts);
}
 

解决方案

请,设置NotifyOnSourceUpdated为true SourceUpdated事件火了:

 <组合框名称=DiscoveredHostsComboBoxVerticalAlignment =中心Grid.Column =0的Horizo​​ntalAlignment =中心=了minWidth100像素的ItemsSource ={绑定路径= DiscoveredHosts ,NotifyOnSourceUpdated = TRUE}SourceUpdated =DiscoveredHostsComboBox_SourceUpdated/>
 

I have DiscoveredHosts which is an ObservableCollection<string>. The sourceupdated event is not being called. Anyone know why?

<ComboBox Name="DiscoveredHostsComboBox" VerticalAlignment="Center" Grid.Column="0"
    HorizontalAlignment="Center" MinWidth="100px" ItemsSource="{Binding Path=
    DiscoveredHosts}" SourceUpdated="DiscoveredHostsComboBox_SourceUpdated" />

public void GetDomainHosts()
{
    DiscoveredHosts.Clear();

    var adapters = NetworkInterface.GetAllNetworkInterfaces();

    if (Config.Debug)
    {
        DiscoveredHosts.Add("192.168.73.11");
        DiscoveredHosts.Add("192.168.73.14");
    }

    foreach (var properties in adapters.Select(adapter => adapter.GetIPProperties()))
    {
        if (properties.DnsSuffix != "" && !DiscoveredHosts.Contains(
properties.DnsSuffix))
            DiscoveredHosts.Add(properties.DnsSuffix);

        if (properties.DnsAddresses.Count <= 0) continue;

        foreach (var host in properties.DnsAddresses.Where(host => !DiscoveredHosts.
Any(a => a == host.ToString())))
            DiscoveredHosts.Add(host.ToString());
    }

    OnPropertyChanged("DiscoveredHosts");
}

解决方案

Please, set NotifyOnSourceUpdated to true for SourceUpdated event to fire:

<ComboBox Name="DiscoveredHostsComboBox" VerticalAlignment="Center" Grid.Column="0" HorizontalAlignment="Center" MinWidth="100px" ItemsSource="{Binding Path=DiscoveredHosts, NotifyOnSourceUpdated=True}" SourceUpdated="DiscoveredHostsComboBox_SourceUpdated" />

这篇关于sourceupdated事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆