Skip to content

Fix: 3099 #3106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NETworkManager.Utilities;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace NETworkManager.Converters;

public sealed class ChildWindowIconToRectangleStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not ChildWindowIcon icon)
return null;

switch (icon)
{
case ChildWindowIcon.Info:
return Application.Current.FindResource("InfoImageRectangle");
case ChildWindowIcon.Warn:
return Application.Current.FindResource("WarnImageRectangle");
case ChildWindowIcon.Error:
return Application.Current.FindResource("ErrorImageRectangle");
default:
return null;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
22 changes: 22 additions & 0 deletions Source/NETworkManager.Utilities/ChildWindowIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NETworkManager.Utilities;

/// <summary>
/// Ions for child dialogs.
/// </summary>
public enum ChildWindowIcon
{
/// <summary>
/// Information icon.
/// </summary>
Info,

/// <summary>
/// Warning icon.
/// </summary>
Warn,

/// <summary>
/// Error icon.
/// </summary>
Error,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-->
<Grid>
<Polygon x:Name="ToolTipCorner" Grid.ZIndex="1" Margin="0" Points="12,12 12,0 0,0"
Fill="{DynamicResource MahApps.Brushes.Accent}" HorizontalAlignment="Right"
Fill="#b95353" HorizontalAlignment="Right"
VerticalAlignment="Top" IsHitTestVisible="True" />
<AdornedElementPlaceholder x:Name="Adorner" />
<Popup PlacementTarget="{Binding ElementName=Adorner}" PopupAnimation="Fade" HorizontalOffset="5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private async Task ShowErrorMessageAsync(HostsFileEntryModifyResult result)
{
childWindow.IsOpen = false;
ConfigurationManager.Current.IsChildWindowOpen = false;
}, message);
}, message, Strings.OK, ChildWindowIcon.Error);

childWindow.Title = Strings.Error;

Expand Down
18 changes: 17 additions & 1 deletion Source/NETworkManager/ViewModels/OKMessageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ namespace NETworkManager.ViewModels;

public class OKMessageViewModel : ViewModelBase
{
public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message, string okButtonText = null)
public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message, string okButtonText = null, ChildWindowIcon icon = ChildWindowIcon.Info)
{
OKCommand = new RelayCommand(_ => okCommand(this));

Message = message;

OKButtonText = okButtonText ?? Localization.Resources.Strings.OK;
Icon = icon;
}

public ICommand OKCommand { get; }
Expand Down Expand Up @@ -46,4 +47,19 @@ private init
OnPropertyChanged();
}
}

private ChildWindowIcon _icon;

public ChildWindowIcon Icon
{
get => _icon;
private init
{
if (value == _icon)
return;

_icon = value;
OnPropertyChanged();
}
}
}
7 changes: 6 additions & 1 deletion Source/NETworkManager/Views/OKMessageChildWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
ChildWindowWidth="450"
ChildWindowMaxHeight="500"
ShowTitleBar="True"
Expand All @@ -17,7 +18,11 @@
CloseByEscape="False"
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKMessageViewModel}">
<simpleChildWindow:ChildWindow.Resources>
<converters:ChildWindowIconToRectangleStyleConverter x:Key="ChildWindowIconToRectangleStyleConverter" />
</simpleChildWindow:ChildWindow.Resources>
<Grid Margin="10">

<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="20" />
Expand All @@ -34,7 +39,7 @@
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Grid.Row="0"
Width="32" Height="32"
Style="{StaticResource InfoImageRectangle}" />
Style="{Binding Icon, Converter={StaticResource ChildWindowIconToRectangleStyleConverter}}" />
<TextBlock Grid.Column="2" Grid.Row="0"
VerticalAlignment="Center"
Text="{Binding Message}"
Expand Down