Skip to content

Commit 4b07dd9

Browse files
authored
Feature: Hide IPv4/6, DNS and DHCP info if adapter is down (#3114)
* Feature: Hide IPv4/6, DNS and DHCP info if adapter is down * Docs: #3111 #3114
1 parent 9ddfea8 commit 4b07dd9

File tree

6 files changed

+297
-60
lines changed

6 files changed

+297
-60
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Linq;
4+
using System.Windows;
5+
using System.Windows.Data;
6+
7+
namespace NETworkManager.Converters;
8+
9+
public sealed class BooleansAndToVisibilityCollapsedConverter : IMultiValueConverter
10+
{
11+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
return values.OfType<bool>().All(b => b) ? Visibility.Visible : Visibility.Collapsed;
14+
}
15+
16+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
}

Source/NETworkManager.Converters/BooleanToVisibilityCollapsedMultiConverter.cs renamed to Source/NETworkManager.Converters/BooleansOrToVisibilityCollapsedConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace NETworkManager.Converters;
88

9-
public sealed class BooleanToVisibilityCollapsedMultiConverter : IMultiValueConverter
9+
public sealed class BooleansOrToVisibilityCollapsedConverter : IMultiValueConverter
1010
{
1111
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
1212
{

Source/NETworkManager.Models/Network/NetworkInterface.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
5454
var ipProperties = networkInterface.GetIPProperties();
5555

5656
foreach (var unicastIPAddrInfo in ipProperties.UnicastAddresses)
57+
{
5758
switch (unicastIPAddrInfo.Address.AddressFamily)
5859
{
5960
case AddressFamily.InterNetwork:
@@ -74,11 +75,13 @@ public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
7475
listIPv6Address.Add(unicastIPAddrInfo.Address);
7576
break;
7677
}
78+
}
7779

7880
var listIPv4Gateway = new List<IPAddress>();
7981
var listIPv6Gateway = new List<IPAddress>();
8082

8183
foreach (var gatewayIPAddrInfo in ipProperties.GatewayAddresses)
84+
{
8285
switch (gatewayIPAddrInfo.Address.AddressFamily)
8386
{
8487
case AddressFamily.InterNetwork:
@@ -88,6 +91,7 @@ public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
8891
listIPv6Gateway.Add(gatewayIPAddrInfo.Address);
8992
break;
9093
}
94+
}
9195

9296
// Check if autoconfiguration for DNS is enabled (only via registry key)
9397
var nameServerKey =

Source/NETworkManager/Views/IPScannerView.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
2525
<converters:BooleanToStringConverter x:Key="BooleanToStringConverter" />
2626
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
27-
<converters:BooleanToVisibilityCollapsedMultiConverter x:Key="BooleanToVisibilityCollapsedMultiConverter" />
27+
<converters:BooleansOrToVisibilityCollapsedConverter x:Key="BooleansOrToVisibilityCollapsedConverter" />
2828
<converters:HostUpStyleConverter x:Key="HostUpStyleConverter" />
2929
<converters:IPStatusToStringConverter x:Key="IPStatusToStringConverter" />
3030
<converters:IntNotZeroToVisibilityCollapsedConverter x:Key="IntNotZeroToVisibilityCollapsedConverter" />
@@ -518,7 +518,7 @@
518518
SortMemberPath="Hostname"
519519
MinWidth="150">
520520
<DataGridTextColumn.Visibility>
521-
<MultiBinding Converter="{StaticResource BooleanToVisibilityCollapsedMultiConverter}">
521+
<MultiBinding Converter="{StaticResource BooleansOrToVisibilityCollapsedConverter}">
522522
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"
523523
Path="IPScanner_ResolveHostname" />
524524
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"
@@ -544,7 +544,7 @@
544544
SortMemberPath="MACAddress"
545545
MinWidth="150">
546546
<DataGridTextColumn.Visibility>
547-
<MultiBinding Converter="{StaticResource BooleanToVisibilityCollapsedMultiConverter}">
547+
<MultiBinding Converter="{StaticResource BooleansOrToVisibilityCollapsedConverter}">
548548
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"
549549
Path="IPScanner_ResolveMACAddress" />
550550
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"
@@ -557,7 +557,7 @@
557557
SortMemberPath="Vendor"
558558
MinWidth="200">
559559
<DataGridTextColumn.Visibility>
560-
<MultiBinding Converter="{StaticResource BooleanToVisibilityCollapsedMultiConverter}">
560+
<MultiBinding Converter="{StaticResource BooleansOrToVisibilityCollapsedConverter}">
561561
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"
562562
Path="IPScanner_ResolveMACAddress" />
563563
<Binding Source="{x:Static Member=settings:SettingsManager.Current}"

0 commit comments

Comments
 (0)