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" />
精彩评论