Skip to content

Commit d8afc2c

Browse files
committed
add controls for notification window customization
- Changed notif windows to bind directly to accent colors so they update - Added translation strings for the new controls - Made exception messages thrown in MultiBindingBooleanConverter useful
1 parent fdec153 commit d8afc2c

File tree

8 files changed

+267
-50
lines changed

8 files changed

+267
-50
lines changed

VolumeControl.WPF/Converters/MultiBindingBooleanConverter.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Globalization;
34
using System.Linq;
45
using System.Windows.Data;
@@ -11,13 +12,27 @@ namespace VolumeControl.WPF.Converters
1112
/// </summary>
1213
public sealed class MultiBindingBooleanConverter : IMultiValueConverter
1314
{
15+
readonly TypeConverter _boolConverter = TypeDescriptor.GetConverter(typeof(bool));
16+
17+
private bool ConvertToBool(object? obj)
18+
{
19+
try
20+
{
21+
return obj != null && System.Convert.ToBoolean(obj);
22+
}
23+
catch (Exception ex)
24+
{
25+
throw new InvalidOperationException($"Failed to convert value \"{obj}\" of type \"{obj?.GetType()}\" to bool!", ex);
26+
}
27+
}
1428
/// <inheritdoc/>
1529
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
1630
{
31+
1732
if (parameter is null || System.Convert.ToBoolean(parameter))
18-
return values.All(i => System.Convert.ToBoolean(i));
33+
return values.All(ConvertToBool);
1934
else
20-
return values.Any(i => System.Convert.ToBoolean(i));
35+
return values.Any(ConvertToBool);
2136
}
2237
/// <inheritdoc/>
2338
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
@@ -26,7 +41,7 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
2641

2742
object[] arr = new object[len];
2843

29-
bool val = System.Convert.ToBoolean(value);
44+
bool val = (bool)value;
3045

3146
for (int i = 0; i < len; ++i)
3247
{

VolumeControl/App.xaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
x:Key="RoundedTextBoxStyle"
419419
BasedOn="{StaticResource TextBoxStyle}"
420420
TargetType="{x:Type TextBox}">
421+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
421422
<Setter Property="Template">
422423
<Setter.Value>
423424
<ControlTemplate TargetType="{x:Type TextBox}">
@@ -440,8 +441,11 @@
440441
<Trigger SourceName="border" Property="IsMouseOver" Value="True">
441442
<Setter Property="BorderBrush" Value="{StaticResource SelectionBorderBrush}" />
442443
</Trigger>
443-
<Trigger SourceName="border" Property="IsKeyboardFocusWithin" Value="True">
444-
<Setter Property="BorderBrush" Value="{StaticResource SelectionBorderBrush}" />
444+
<Trigger Property="IsKeyboardFocused" Value="True">
445+
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource SelectionBorderBrush}" />
446+
</Trigger>
447+
<Trigger Property="IsFocused" Value="True">
448+
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource SelectionBorderBrush}" />
445449
</Trigger>
446450
</ControlTemplate.Triggers>
447451
</ControlTemplate>
@@ -838,7 +842,7 @@
838842
<Setter Property="Focusable" Value="False" />
839843
<Setter Property="BorderThickness" Value="0" />
840844
<Setter Property="Template" Value="{StaticResource ExpanderTemplate}" />
841-
<Setter Property="FocusVisualStyle" Value="{DynamicResource CustomFocusVisualStyle}" />
845+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
842846
</Style>
843847
<!-- TextBoxWithCompletionOptions Style -->
844848
<Style x:Key="TextBoxWithCompletionOptionsStyle" TargetType="{x:Type controls:TextBoxWithCompletionOptions}">

VolumeControl/DeviceListNotification.xaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
<BooleanToVisibilityConverter />
4141
</conv:ConverterChain>
4242
<conv:BooleanInverter x:Key="InvertConverter" />
43-
<conv:BoolToBrushConverter
44-
x:Key="SelectedItemBackgroundBrushConverter"
45-
WhenFalse="{Binding DeviceConfigVM.UnlockedAccentBrush, Source={StaticResource Settings}}"
46-
WhenTrue="{Binding DeviceConfigVM.LockedAccentBrush, Source={StaticResource Settings}}" />
4743

4844
<!-- Styles -->
4945
<Style BasedOn="{StaticResource CheckBoxStyle}" TargetType="{x:Type CheckBox}" />
@@ -205,10 +201,21 @@
205201
<Border
206202
Padding="9"
207203
Background="{Binding VM.BackgroundBrush}"
208-
BorderBrush="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}, Converter={StaticResource SelectedItemBackgroundBrushConverter}}"
209204
BorderThickness="7"
210205
CornerRadius="{Binding VM.ConfigSection.CornerRadius}"
211206
RenderOptions.EdgeMode="Aliased">
207+
<Border.Style>
208+
<Style TargetType="{x:Type Border}">
209+
<Style.Triggers>
210+
<DataTrigger Binding="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}}" Value="True">
211+
<Setter Property="BorderBrush" Value="{Binding DeviceConfigVM.LockedAccentBrush, Source={StaticResource Settings}}" />
212+
</DataTrigger>
213+
<DataTrigger Binding="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}}" Value="False">
214+
<Setter Property="BorderBrush" Value="{Binding DeviceConfigVM.UnlockedAccentBrush, Source={StaticResource Settings}}" />
215+
</DataTrigger>
216+
</Style.Triggers>
217+
</Style>
218+
</Border.Style>
212219
<Grid>
213220
<Grid.RowDefinitions>
214221
<RowDefinition Height="Auto" />
@@ -244,10 +251,26 @@
244251
<ListView.ItemContainerStyle>
245252
<Style TargetType="{x:Type ListViewItem}">
246253
<Style.Triggers>
247-
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
248-
<Setter Property="FontWeight" Value="Bold" />
249-
<Setter Property="Background" Value="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}, Converter={StaticResource SelectedItemBackgroundBrushConverter}}" />
250-
</DataTrigger>
254+
<MultiDataTrigger>
255+
<MultiDataTrigger.Conditions>
256+
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />
257+
<Condition Binding="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}}" Value="True" />
258+
</MultiDataTrigger.Conditions>
259+
<MultiDataTrigger.Setters>
260+
<Setter Property="FontWeight" Value="Bold" />
261+
<Setter Property="Background" Value="{Binding DeviceConfigVM.LockedAccentBrush, Source={StaticResource Settings}}" />
262+
</MultiDataTrigger.Setters>
263+
</MultiDataTrigger>
264+
<MultiDataTrigger>
265+
<MultiDataTrigger.Conditions>
266+
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />
267+
<Condition Binding="{Binding AudioAPI.AudioDeviceSelector.LockSelection, Source={StaticResource Settings}}" Value="False" />
268+
</MultiDataTrigger.Conditions>
269+
<MultiDataTrigger.Setters>
270+
<Setter Property="FontWeight" Value="Bold" />
271+
<Setter Property="Background" Value="{Binding DeviceConfigVM.UnlockedAccentBrush, Source={StaticResource Settings}}" />
272+
</MultiDataTrigger.Setters>
273+
</MultiDataTrigger>
251274
</Style.Triggers>
252275
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
253276
<Setter Property="FocusVisualStyle" Value="{x:Null}" />

VolumeControl/Localization/en.loc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,36 @@
311311
},
312312
"Tooltip": {}
313313
}
314+
},
315+
"ColorPicker": {
316+
"Background": {
317+
"Tooltip": {
318+
"English (US/CA)": "Sets the background color of the notification window."
319+
}
320+
},
321+
"Foreground": {
322+
"Tooltip": {
323+
"English (US/CA)": "Sets the text color of the notification window."
324+
}
325+
},
326+
"LockedAccent": {
327+
"Tooltip": {
328+
"English (US/CA)": "Sets the accent color of the notification window when selection is locked."
329+
}
330+
},
331+
"UnlockedAccent": {
332+
"Tooltip": {
333+
"English (US/CA)": "Sets the accent color of the notification window when selection is unlocked."
334+
}
335+
}
336+
},
337+
"CornerRadius": {
338+
"Content": {
339+
"English (US/CA)": "Corner Radius:"
340+
},
341+
"Tooltip": {
342+
"English (US/CA)": "The radius of the corners of the notification window. Starts at the top-left corner and goes clockwise."
343+
}
314344
}
315345
},
316346
"Log": {

0 commit comments

Comments
 (0)