Skip to content

Commit 4769fcd

Browse files
authored
Fix: 3099 (#3106)
1 parent 9daa292 commit 4769fcd

File tree

6 files changed

+80
-4
lines changed

6 files changed

+80
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using NETworkManager.Utilities;
2+
using System;
3+
using System.Globalization;
4+
using System.Windows;
5+
using System.Windows.Data;
6+
7+
namespace NETworkManager.Converters;
8+
9+
public sealed class ChildWindowIconToRectangleStyleConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (value is not ChildWindowIcon icon)
14+
return null;
15+
16+
switch (icon)
17+
{
18+
case ChildWindowIcon.Info:
19+
return Application.Current.FindResource("InfoImageRectangle");
20+
case ChildWindowIcon.Warn:
21+
return Application.Current.FindResource("WarnImageRectangle");
22+
case ChildWindowIcon.Error:
23+
return Application.Current.FindResource("ErrorImageRectangle");
24+
default:
25+
return null;
26+
}
27+
}
28+
29+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NETworkManager.Utilities;
2+
3+
/// <summary>
4+
/// Ions for child dialogs.
5+
/// </summary>
6+
public enum ChildWindowIcon
7+
{
8+
/// <summary>
9+
/// Information icon.
10+
/// </summary>
11+
Info,
12+
13+
/// <summary>
14+
/// Warning icon.
15+
/// </summary>
16+
Warn,
17+
18+
/// <summary>
19+
/// Error icon.
20+
/// </summary>
21+
Error,
22+
}

Source/NETworkManager/Resources/Templates/ValidationErrorTemplates.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
-->
1212
<Grid>
1313
<Polygon x:Name="ToolTipCorner" Grid.ZIndex="1" Margin="0" Points="12,12 12,0 0,0"
14-
Fill="{DynamicResource MahApps.Brushes.Accent}" HorizontalAlignment="Right"
14+
Fill="#b95353" HorizontalAlignment="Right"
1515
VerticalAlignment="Top" IsHitTestVisible="True" />
1616
<AdornedElementPlaceholder x:Name="Adorner" />
1717
<Popup PlacementTarget="{Binding ElementName=Adorner}" PopupAnimation="Fade" HorizontalOffset="5">

Source/NETworkManager/ViewModels/HostsFileEditorViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private async Task ShowErrorMessageAsync(HostsFileEntryModifyResult result)
452452
{
453453
childWindow.IsOpen = false;
454454
ConfigurationManager.Current.IsChildWindowOpen = false;
455-
}, message);
455+
}, message, Strings.OK, ChildWindowIcon.Error);
456456

457457
childWindow.Title = Strings.Error;
458458

Source/NETworkManager/ViewModels/OKMessageViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ namespace NETworkManager.ViewModels;
66

77
public class OKMessageViewModel : ViewModelBase
88
{
9-
public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message, string okButtonText = null)
9+
public OKMessageViewModel(Action<OKMessageViewModel> okCommand, string message, string okButtonText = null, ChildWindowIcon icon = ChildWindowIcon.Info)
1010
{
1111
OKCommand = new RelayCommand(_ => okCommand(this));
1212

1313
Message = message;
1414

1515
OKButtonText = okButtonText ?? Localization.Resources.Strings.OK;
16+
Icon = icon;
1617
}
1718

1819
public ICommand OKCommand { get; }
@@ -46,4 +47,19 @@ private init
4647
OnPropertyChanged();
4748
}
4849
}
50+
51+
private ChildWindowIcon _icon;
52+
53+
public ChildWindowIcon Icon
54+
{
55+
get => _icon;
56+
private init
57+
{
58+
if (value == _icon)
59+
return;
60+
61+
_icon = value;
62+
OnPropertyChanged();
63+
}
64+
}
4965
}

Source/NETworkManager/Views/OKMessageChildWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
88
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
99
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
10+
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
1011
ChildWindowWidth="450"
1112
ChildWindowMaxHeight="500"
1213
ShowTitleBar="True"
@@ -17,7 +18,11 @@
1718
CloseByEscape="False"
1819
OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}"
1920
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:OKMessageViewModel}">
21+
<simpleChildWindow:ChildWindow.Resources>
22+
<converters:ChildWindowIconToRectangleStyleConverter x:Key="ChildWindowIconToRectangleStyleConverter" />
23+
</simpleChildWindow:ChildWindow.Resources>
2024
<Grid Margin="10">
25+
2126
<Grid.RowDefinitions>
2227
<RowDefinition Height="*" />
2328
<RowDefinition Height="20" />
@@ -34,7 +39,7 @@
3439
</Grid.ColumnDefinitions>
3540
<Rectangle Grid.Column="0" Grid.Row="0"
3641
Width="32" Height="32"
37-
Style="{StaticResource InfoImageRectangle}" />
42+
Style="{Binding Icon, Converter={StaticResource ChildWindowIconToRectangleStyleConverter}}" />
3843
<TextBlock Grid.Column="2" Grid.Row="0"
3944
VerticalAlignment="Center"
4045
Text="{Binding Message}"

0 commit comments

Comments
 (0)