开发者

sourceupdated event not firing

开发者 https://www.devze.com 2023-02-22 04:03 出处:网络
I have DiscoveredHosts which is an ObservableCollection<string&g开发者_如何学Got;.The sourceupdated event is not being called.Anyone know why?

I have DiscoveredHosts which is an ObservableCollection<string&g开发者_如何学Got;. 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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消