A:调整文字展示效果
This commit is contained in:
1 parent
5b7abd1ef3
commit
c8207a2c85
6 files changed
+162
-16
No files matched your search
@@ -2,8 +2,8 @@
|
|||||||
x:Class="Shell.App"
|
x:Class="Shell.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:NetVizor"
|
xmlns:local="clr-namespace:Shell"
|
||||||
xmlns:converters="clr-namespace:NetVizor.Views.Converters">
|
xmlns:converters="clr-namespace:Shell.Converters">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<converters:NullToCollapsedConverter
|
<converters:NullToCollapsedConverter
|
||||||
@@ -27,4 +27,4 @@
|
|||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
@@ -3,7 +3,7 @@ using System.Globalization;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
|
||||||
namespace NetVizor.Views.Converters
|
namespace Shell.Converters
|
||||||
{
|
{
|
||||||
public class NullToCollapsedConverter : IValueConverter
|
public class NullToCollapsedConverter : IValueConverter
|
||||||
{
|
{
|
||||||
@@ -30,4 +30,27 @@ namespace NetVizor.Views.Converters
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public class InvertedBooleanToVisibilityConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is bool boolValue)
|
||||||
|
{
|
||||||
|
return boolValue ? Visibility.Collapsed : Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is Visibility visibility)
|
||||||
|
{
|
||||||
|
return visibility == Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,17 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:viewModel="clr-namespace:Shell.ViewModel"
|
xmlns:viewModel="clr-namespace:Shell.ViewModel"
|
||||||
|
xmlns:converters="clr-namespace:Shell.Converters"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="120"
|
d:DesignHeight="120"
|
||||||
d:DesignWidth="200"
|
d:DesignWidth="200"
|
||||||
Background="Transparent">
|
Background="Transparent">
|
||||||
|
|
||||||
|
<UserControl.Resources>
|
||||||
|
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||||
|
<converters:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
|
|
||||||
<d:UserControl.DataContext>
|
<d:UserControl.DataContext>
|
||||||
<viewModel:NetworkMonitorViewModel />
|
<viewModel:NetworkMonitorViewModel />
|
||||||
</d:UserControl.DataContext>
|
</d:UserControl.DataContext>
|
||||||
@@ -102,10 +108,24 @@
|
|||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<!-- App Icon -->
|
<!-- App Icon or Initial Letter -->
|
||||||
<Image Grid.Column="0" Width="12" Height="12"
|
<Grid Grid.Column="0" Width="12" Height="12" VerticalAlignment="Center">
|
||||||
Source="{Binding IconSource}"
|
<!-- Process Icon -->
|
||||||
VerticalAlignment="Center" />
|
<Image Source="{Binding IconSource}"
|
||||||
|
Visibility="{Binding HasIcon, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||||
|
<!-- Initial Letter Fallback -->
|
||||||
|
<Border Background="{Binding InitialBackgroundColor}"
|
||||||
|
CornerRadius="6"
|
||||||
|
Visibility="{Binding HasIcon, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
|
||||||
|
<TextBlock Text="{Binding InitialLetter}"
|
||||||
|
FontSize="8"
|
||||||
|
FontWeight="Bold"
|
||||||
|
Foreground="White"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Margin="0,-1,0,0" />
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<!-- App Name -->
|
<!-- App Name -->
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
@@ -125,11 +145,11 @@
|
|||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<TextBlock Grid.Column="0" Text="↑"
|
<TextBlock Grid.Column="0" Text="↑"
|
||||||
Foreground="#FF6B6B" FontSize="9"
|
Foreground="#FF6B6B" FontSize="10"
|
||||||
VerticalAlignment="Center" Margin="0,0,2,0" />
|
VerticalAlignment="Center" Margin="0,0,2,0" />
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
Text="{Binding FormattedUploadSpeed}"
|
Text="{Binding FormattedUploadSpeed}"
|
||||||
FontSize="9" FontWeight="Normal"
|
FontSize="10" FontWeight="Normal"
|
||||||
Foreground="#666666"
|
Foreground="#666666"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Width="40"
|
Width="40"
|
||||||
@@ -144,11 +164,11 @@
|
|||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<TextBlock Grid.Column="0" Text="↓"
|
<TextBlock Grid.Column="0" Text="↓"
|
||||||
Foreground="#4ECDC4" FontSize="9"
|
Foreground="#4ECDC4" FontSize="10"
|
||||||
VerticalAlignment="Center" Margin="0,0,2,0" />
|
VerticalAlignment="Center" Margin="0,0,2,0" />
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
Text="{Binding FormattedDownloadSpeed}"
|
Text="{Binding FormattedDownloadSpeed}"
|
||||||
FontSize="9" FontWeight="Normal"
|
FontSize="10" FontWeight="Normal"
|
||||||
Foreground="#666666"
|
Foreground="#666666"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Width="40"
|
Width="40"
|
||||||
|
|||||||
@@ -156,6 +156,10 @@ public class NetworkMonitorViewModel : INotifyPropertyChanged
|
|||||||
// 初始化数据
|
// 初始化数据
|
||||||
LoadNetworkInterfaces();
|
LoadNetworkInterfaces();
|
||||||
LoadTopListSettings();
|
LoadTopListSettings();
|
||||||
|
|
||||||
|
// 监听NetViewSettings的变更
|
||||||
|
NetViewSettings.Instance.PropertyChanged += OnNetViewSettingsChanged;
|
||||||
|
|
||||||
_updateTimer.Start();
|
_updateTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,6 +464,19 @@ public class NetworkMonitorViewModel : INotifyPropertyChanged
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理NetViewSettings变更事件
|
||||||
|
/// </summary>
|
||||||
|
private void OnNetViewSettingsChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(NetViewSettings.ShowNetworkTopList) ||
|
||||||
|
e.PropertyName == nameof(NetViewSettings.NetworkTopListCount) ||
|
||||||
|
e.PropertyName == nameof(NetViewSettings.LayoutDirection))
|
||||||
|
{
|
||||||
|
UpdateTopListVisibility();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新Top榜可见性
|
/// 更新Top榜可见性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -626,6 +643,9 @@ public class NetworkMonitorViewModel : INotifyPropertyChanged
|
|||||||
|
|
||||||
Log.Info("NetworkMonitorViewModel 销毁");
|
Log.Info("NetworkMonitorViewModel 销毁");
|
||||||
_updateTimer?.Stop();
|
_updateTimer?.Stop();
|
||||||
|
|
||||||
|
// 取消事件监听
|
||||||
|
NetViewSettings.Instance.PropertyChanged -= OnNetViewSettingsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using Utils.ETW.Models;
|
using Utils.ETW.Models;
|
||||||
|
|
||||||
@@ -61,9 +62,25 @@ public class ProcessNetworkStatsViewModel : INotifyPropertyChanged
|
|||||||
{
|
{
|
||||||
_iconSource = value;
|
_iconSource = value;
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
|
OnPropertyChanged(nameof(HasIcon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否有图标
|
||||||
|
/// </summary>
|
||||||
|
public bool HasIcon => _iconSource != null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 首字母
|
||||||
|
/// </summary>
|
||||||
|
public string InitialLetter => GetInitialLetter();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 首字母背景色
|
||||||
|
/// </summary>
|
||||||
|
public System.Windows.Media.Brush InitialBackgroundColor => GetInitialBackgroundColor();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新统计数据
|
/// 更新统计数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -76,6 +93,10 @@ public class ProcessNetworkStatsViewModel : INotifyPropertyChanged
|
|||||||
OnPropertyChanged(nameof(FormattedTotalSpeed));
|
OnPropertyChanged(nameof(FormattedTotalSpeed));
|
||||||
OnPropertyChanged(nameof(TotalSpeed));
|
OnPropertyChanged(nameof(TotalSpeed));
|
||||||
|
|
||||||
|
// 通知首字母相关属性更新
|
||||||
|
OnPropertyChanged(nameof(InitialLetter));
|
||||||
|
OnPropertyChanged(nameof(InitialBackgroundColor));
|
||||||
|
|
||||||
// 如果图标还未加载,尝试重新加载
|
// 如果图标还未加载,尝试重新加载
|
||||||
if (_iconSource == null)
|
if (_iconSource == null)
|
||||||
{
|
{
|
||||||
@@ -117,6 +138,59 @@ public class ProcessNetworkStatsViewModel : INotifyPropertyChanged
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取进程名首字母
|
||||||
|
/// </summary>
|
||||||
|
private string GetInitialLetter()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ProcessName))
|
||||||
|
return "?";
|
||||||
|
|
||||||
|
var name = ProcessName.Trim();
|
||||||
|
if (name.Length == 0)
|
||||||
|
return "?";
|
||||||
|
|
||||||
|
// 获取第一个字符,转为大写
|
||||||
|
var firstChar = name[0];
|
||||||
|
if (char.IsLetter(firstChar))
|
||||||
|
{
|
||||||
|
return char.ToUpper(firstChar).ToString();
|
||||||
|
}
|
||||||
|
else if (char.IsDigit(firstChar))
|
||||||
|
{
|
||||||
|
return firstChar.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据进程名生成背景色
|
||||||
|
/// </summary>
|
||||||
|
private System.Windows.Media.Brush GetInitialBackgroundColor()
|
||||||
|
{
|
||||||
|
var colors = new[]
|
||||||
|
{
|
||||||
|
"#FF5722", "#E91E63", "#9C27B0", "#673AB7", "#3F51B5",
|
||||||
|
"#2196F3", "#03A9F4", "#00BCD4", "#009688", "#4CAF50",
|
||||||
|
"#8BC34A", "#CDDC39", "#FFC107", "#FF9800", "#FF5722"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(ProcessName))
|
||||||
|
{
|
||||||
|
return new SolidColorBrush(
|
||||||
|
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#9E9E9E"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用进程名的哈希值来选择颜色,确保同名进程使用相同颜色
|
||||||
|
var hash = ProcessName.GetHashCode();
|
||||||
|
var index = Math.Abs(hash) % colors.Length;
|
||||||
|
return new SolidColorBrush(
|
||||||
|
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(colors[index]));
|
||||||
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||||
|
|||||||
@@ -594,9 +594,18 @@ public partial class SettingsWindow : Window
|
|||||||
.GetMethod("OnPropertyChanged",
|
.GetMethod("OnPropertyChanged",
|
||||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||||
|
|
||||||
propertyChangedMethod?.Invoke(netViewSettings, new object[] { "ShowNetworkTopList" });
|
if (propertyChangedMethod != null)
|
||||||
propertyChangedMethod?.Invoke(netViewSettings, new object[] { "NetworkTopListCount" });
|
{
|
||||||
propertyChangedMethod?.Invoke(netViewSettings, new object[] { "IsTopListAvailable" });
|
propertyChangedMethod.Invoke(netViewSettings, new object[] { "ShowNetworkTopList" });
|
||||||
|
propertyChangedMethod.Invoke(netViewSettings, new object[] { "NetworkTopListCount" });
|
||||||
|
propertyChangedMethod.Invoke(netViewSettings, new object[] { "LayoutDirection" });
|
||||||
|
propertyChangedMethod.Invoke(netViewSettings, new object[] { "IsTopListAvailable" });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 备用方案:保存设置到NetViewSettings的json文件
|
||||||
|
netViewSettings.SaveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Info("NetworkMonitorViewModel 排行榜显示已刷新");
|
Log.Info("NetworkMonitorViewModel 排行榜显示已刷新");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user