Skip to content

Commit c9652d1

Browse files
BornToBeRootclaude
andcommitted
Chore: Run command: Application icon without binding in a style setter
The application icon of the run command (command and suggestions) was a VisualBrush with a binding in the Setter.Value of a style. The brush belongs to the style, not to the element, so the binding had no element to resolve against and was logged as XAML binding error (for every suggestion). New ApplicationNameToIconBrushConverter, the setter value is the binding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a013506 commit c9652d1

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using System.Windows.Media;
5+
using NETworkManager.Models;
6+
7+
namespace NETworkManager.Converters;
8+
9+
/// <summary>
10+
/// Convert <see cref="ApplicationName" /> to its icon as <see cref="VisualBrush" /> (e.g. for an OpacityMask). Can be
11+
/// used as value of a style setter, unlike a <see cref="VisualBrush" /> with a binding in the setter, which has no
12+
/// element to resolve the binding against.
13+
/// </summary>
14+
public sealed class ApplicationNameToIconBrushConverter : IValueConverter
15+
{
16+
/// <summary>
17+
/// Convert <see cref="ApplicationName" /> to its icon as <see cref="VisualBrush" />.
18+
/// </summary>
19+
/// <param name="value">Object from type <see cref="ApplicationName" />.</param>
20+
/// <param name="targetType"></param>
21+
/// <param name="parameter"></param>
22+
/// <param name="culture"></param>
23+
/// <returns>Icon as <see cref="VisualBrush" />.</returns>
24+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
25+
{
26+
return value is not ApplicationName name
27+
? null
28+
: new VisualBrush(ApplicationManager.GetIcon(name)) { Stretch = Stretch.Uniform };
29+
}
30+
31+
/// <summary>
32+
/// !!! Method not implemented !!!
33+
/// </summary>
34+
/// <param name="value"></param>
35+
/// <param name="targetType"></param>
36+
/// <param name="parameter"></param>
37+
/// <param name="culture"></param>
38+
/// <returns></returns>
39+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
40+
{
41+
throw new NotImplementedException();
42+
}
43+
}

‎Source/NETworkManager/Views/RunCommandChildWindow.xaml‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Loaded="ChildWindow_OnLoaded"
2323
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:RunCommandViewModel}">
2424
<simpleChildWindow:ChildWindow.Resources>
25-
<converters:ApplicationNameToIconConverter x:Key="ApplicationNameToIconConverter" />
25+
<converters:ApplicationNameToIconBrushConverter x:Key="ApplicationNameToIconBrushConverter" />
2626
<converters:StringIsNotNullOrEmptyToVisibilityCollapsedConverter
2727
x:Key="StringIsNotNullOrEmptyToVisibilityCollapsedConverter" />
2828
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
@@ -88,12 +88,7 @@
8888
<Rectangle.Style>
8989
<Style TargetType="{x:Type Rectangle}">
9090
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
91-
<Setter Property="OpacityMask">
92-
<Setter.Value>
93-
<VisualBrush Stretch="Uniform"
94-
Visual="{Binding CommandApplication, Converter={StaticResource ApplicationNameToIconConverter}}" />
95-
</Setter.Value>
96-
</Setter>
91+
<Setter Property="OpacityMask" Value="{Binding CommandApplication, Converter={StaticResource ApplicationNameToIconBrushConverter}}" />
9792
<Style.Triggers>
9893
<DataTrigger Binding="{Binding CommandApplication}"
9994
Value="{x:Static models:ApplicationName.None}">
@@ -264,12 +259,7 @@
264259
<Rectangle.Style>
265260
<Style TargetType="{x:Type Rectangle}">
266261
<!-- Application icon (command, target, example, history) -->
267-
<Setter Property="OpacityMask">
268-
<Setter.Value>
269-
<VisualBrush Stretch="Uniform"
270-
Visual="{Binding Application, Converter={StaticResource ApplicationNameToIconConverter}}" />
271-
</Setter.Value>
272-
</Setter>
262+
<Setter Property="OpacityMask" Value="{Binding Application, Converter={StaticResource ApplicationNameToIconBrushConverter}}" />
273263
<Style.Triggers>
274264
<DataTrigger Binding="{Binding Application}"
275265
Value="{x:Static models:ApplicationName.None}">

0 commit comments

Comments
 (0)