Skip to content

Commit a464709

Browse files
BornToBeRootclaude
andcommitted
Chore: Icons of lists without binding in a VisualBrush
The icons of the settings list, the profile / group dialog and the application list of the main window were a VisualBrush with a binding on Visual. The brush is no element, in some cases its binding had nothing to resolve against and was logged as XAML binding error. The OpacityMask of the Rectangle is bound instead, with a converter that creates the brush (new VisualToVisualBrushConverter, ApplicationNameToIconBrushConverter). ApplicationNameToIconConverter is no longer used and removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6787342 commit a464709

5 files changed

Lines changed: 23 additions & 28 deletions

File tree

Source/NETworkManager.Converters/ApplicationNameToIconConverter.cs renamed to Source/NETworkManager.Converters/VisualToVisualBrushConverter.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
using System;
1+
using System;
22
using System.Globalization;
3-
using System.Windows.Controls;
43
using System.Windows.Data;
5-
using NETworkManager.Models;
4+
using System.Windows.Media;
65

76
namespace NETworkManager.Converters;
87

98
/// <summary>
10-
/// Convert <see cref="ApplicationName" /> to icon (<see cref="Canvas" />) or wise versa.
9+
/// Convert a <see cref="Visual" /> (e.g. an icon) to a <see cref="VisualBrush" /> (e.g. for an OpacityMask). The
10+
/// binding is on the element, unlike a <see cref="VisualBrush" /> with a binding on <see cref="VisualBrush.Visual" />,
11+
/// which has no element to resolve the binding against in some cases (logged as XAML binding error).
1112
/// </summary>
12-
public sealed class ApplicationNameToIconConverter : IValueConverter
13+
public sealed class VisualToVisualBrushConverter : IValueConverter
1314
{
1415
/// <summary>
15-
/// Convert <see cref="ApplicationName" /> to icon (<see cref="Canvas" />).
16+
/// Convert a <see cref="Visual" /> to a <see cref="VisualBrush" />.
1617
/// </summary>
17-
/// <param name="value">Object from type <see cref="ApplicationName" />.</param>
18+
/// <param name="value">Object from type <see cref="Visual" />.</param>
1819
/// <param name="targetType"></param>
1920
/// <param name="parameter"></param>
2021
/// <param name="culture"></param>
21-
/// <returns>Icon (cref="Canvas"/>).</returns>
22+
/// <returns><see cref="VisualBrush" /> of the visual.</returns>
2223
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2324
{
24-
return value is not ApplicationName name ? null : ApplicationManager.GetIcon(name);
25+
return value is not Visual visual ? null : new VisualBrush(visual) { Stretch = Stretch.Uniform };
2526
}
2627

2728
/// <summary>
@@ -36,4 +37,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
3637
{
3738
throw new NotImplementedException();
3839
}
39-
}
40+
}

‎Source/NETworkManager/MainWindow.xaml‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
d:DataContext="{d:DesignInstance networkManager:MainWindow}">
2828
<!-- MetroDialogStyles.xaml must be adjusted if MinWidth/MinHeight is changed -->
2929
<mah:MetroWindow.Resources>
30+
<converters:ApplicationNameToIconBrushConverter x:Key="ApplicationNameToIconBrushConverter" />
3031
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
3132
<converters:BooleanReverseConverter x:Key="BooleanReverseConverter"></converters:BooleanReverseConverter>
3233
<converters:ApplicationNameToTranslatedStringConverter x:Key="ApplicationNameToTranslatedStringConverter" />
33-
<converters:ApplicationNameToIconConverter x:Key="ApplicationNameToIconConverter" />
3434
<converters:IntZeroToVisibilityCollapsedConverter x:Key="IntZeroToVisibilityCollapsedConverter" />
3535
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
3636
<!-- ReSharper disable once Xaml.RedundantResource - Used in TrayIcon -->
@@ -696,11 +696,8 @@
696696
</Style>
697697
</Rectangle.Style>
698698
</Rectangle>
699-
<Rectangle Grid.Column="0" Width="24" Height="24" Margin="0,0,-2,0">
700-
<Rectangle.OpacityMask>
701-
<VisualBrush Stretch="Uniform"
702-
Visual="{Binding Name, Converter={StaticResource ApplicationNameToIconConverter}}" />
703-
</Rectangle.OpacityMask>
699+
<Rectangle Grid.Column="0" Width="24" Height="24" Margin="0,0,-2,0"
700+
OpacityMask="{Binding Name, Converter={StaticResource ApplicationNameToIconBrushConverter}}">
704701
<Rectangle.Style>
705702
<Style TargetType="{x:Type Rectangle}">
706703
<Setter Property="Fill"

‎Source/NETworkManager/Views/GroupChildWindow.xaml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Loaded="ChildWindow_OnLoaded"
2525
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:GroupViewModel}">
2626
<simpleChildWindow:ChildWindow.Resources>
27+
<converters:VisualToVisualBrushConverter x:Key="VisualToVisualBrushConverter" />
2728
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
2829
<converters:RemoteDesktopAudioCaptureRedirectionModeToStringConverter x:Key="RemoteDesktopAudioCaptureRedirectionModeToStringConverter" />
2930
<converters:RemoteDesktopAudioRedirectionModeToStringConverter x:Key="RemoteDesktopAudioRedirectionModeToStringConverter" />
@@ -60,10 +61,8 @@
6061
<ColumnDefinition Width="10" />
6162
<ColumnDefinition Width="Auto" />
6263
</Grid.ColumnDefinitions>
63-
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0">
64-
<Rectangle.OpacityMask>
65-
<VisualBrush Stretch="Uniform" Visual="{Binding Icon}" />
66-
</Rectangle.OpacityMask>
64+
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0"
65+
OpacityMask="{Binding Icon, Converter={StaticResource VisualToVisualBrushConverter}}">
6766
<Rectangle.Style>
6867
<Style TargetType="{x:Type Rectangle}">
6968
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />

‎Source/NETworkManager/Views/ProfileChildWindow.xaml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Loaded="ChildWindow_OnLoaded"
2626
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:ProfileViewModel}">
2727
<simpleChildWindow:ChildWindow.Resources>
28+
<converters:VisualToVisualBrushConverter x:Key="VisualToVisualBrushConverter" />
2829
<converters:BooleanReverseConverter x:Key="BooleanReverseConverter" />
2930
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
3031
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
@@ -75,10 +76,8 @@
7576
<ColumnDefinition Width="10" />
7677
<ColumnDefinition Width="Auto" />
7778
</Grid.ColumnDefinitions>
78-
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0">
79-
<Rectangle.OpacityMask>
80-
<VisualBrush Stretch="Uniform" Visual="{Binding Icon}" />
81-
</Rectangle.OpacityMask>
79+
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0"
80+
OpacityMask="{Binding Icon, Converter={StaticResource VisualToVisualBrushConverter}}">
8281
<Rectangle.Style>
8382
<Style TargetType="{x:Type Rectangle}">
8483
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />

‎Source/NETworkManager/Views/SettingsView.xaml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
1313
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:SettingsViewModel}">
1414
<UserControl.Resources>
15+
<converters:VisualToVisualBrushConverter x:Key="VisualToVisualBrushConverter" />
1516
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
1617
<converters:SettingsGroupToTranslatedStringConverter x:Key="SettingsGroupToTranslatedStringConverter" />
1718
<converters:SettingsNameToTranslatedStringConverter x:Key="SettingsNameToTranslatedStringConverter" />
@@ -73,10 +74,8 @@
7374
<ColumnDefinition Width="Auto" />
7475
<ColumnDefinition Width="*" />
7576
</Grid.ColumnDefinitions>
76-
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0">
77-
<Rectangle.OpacityMask>
78-
<VisualBrush Stretch="Uniform" Visual="{Binding Icon}" />
79-
</Rectangle.OpacityMask>
77+
<Rectangle Grid.Column="0" Width="20" Height="20" Margin="10,0"
78+
OpacityMask="{Binding Icon, Converter={StaticResource VisualToVisualBrushConverter}}">
8079
<Rectangle.Style>
8180
<Style TargetType="{x:Type Rectangle}">
8281
<Setter Property="Fill"

0 commit comments

Comments
 (0)