Skip to content

Commit 6378716

Browse files
authored
Allow for transparent colors for generated icons (#3273)
1 parent 06820dc commit 6378716

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
using System.Windows.Media;
4+
5+
namespace MaterialDesignDemo.Converters;
6+
7+
public class IsTransparentConverter : IValueConverter
8+
{
9+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
10+
{
11+
Color? color = value switch
12+
{
13+
Color c => c,
14+
SolidColorBrush brush => brush.Color,
15+
_ => null
16+
};
17+
return color == Colors.Transparent;
18+
}
19+
20+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
21+
{
22+
if (value is bool boolValue &&
23+
boolValue)
24+
{
25+
return Colors.Transparent;
26+
}
27+
return Binding.DoNothing;
28+
}
29+
}

MainDemo.Wpf/IconPack.xaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<materialDesign:NullableToVisibilityConverter x:Key="NullableToVisibilityConverter" />
2525
<converters:StringJoinConverter x:Key="StringJoinConverter" Separator="{x:Static system:Environment.NewLine}" />
2626
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter" />
27+
<converters:IsTransparentConverter x:Key="IsTransparentConverter" />
2728
</ResourceDictionary>
2829
</UserControl.Resources>
2930

@@ -191,22 +192,45 @@
191192
</StackPanel>
192193
</Grid>
193194

194-
<materialDesign:ColorPicker MinHeight="100" Margin="0,10">
195+
<materialDesign:ColorPicker MinHeight="100" Margin="0,10"
196+
IsEnabled="{Binding IsChecked, ElementName=UseTransparent, Converter={StaticResource InvertBooleanConverter}}">
195197
<materialDesign:ColorPicker.Style>
196198
<Style TargetType="materialDesign:ColorPicker" BasedOn="{StaticResource {x:Type materialDesign:ColorPicker}}">
197199
<Setter Property="Color" Value="{Binding GeneratedIconBackground, Delay=25}" />
198200
<Style.Triggers>
199201
<DataTrigger Binding="{Binding IsChecked, ElementName=IconForeground}" Value="True">
200202
<Setter Property="Color" Value="{Binding GeneratedIconForeground, Delay=25}" />
201203
</DataTrigger>
204+
<Trigger Property="IsEnabled" Value="False">
205+
<Setter Property="Opacity" Value="0.4" />
206+
</Trigger>
202207
</Style.Triggers>
203208
</Style>
204209
</materialDesign:ColorPicker.Style>
205210
</materialDesign:ColorPicker>
206211

207-
<Button HorizontalAlignment="Right"
208-
Command="{Binding SaveIconCommand}"
209-
Content="_Save" />
212+
<Grid>
213+
<Grid.ColumnDefinitions>
214+
<ColumnDefinition />
215+
<ColumnDefinition Width="Auto" />
216+
</Grid.ColumnDefinitions>
217+
<CheckBox Content="Use Transparent" x:Name="UseTransparent">
218+
<CheckBox.Style>
219+
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
220+
<Setter Property="IsChecked" Value="{Binding GeneratedIconBackground, Converter={StaticResource IsTransparentConverter}}" />
221+
<Style.Triggers>
222+
<DataTrigger Binding="{Binding IsChecked, ElementName=IconForeground}" Value="True">
223+
<Setter Property="IsChecked" Value="{Binding GeneratedIconForeground, Converter={StaticResource IsTransparentConverter}}" />
224+
</DataTrigger>
225+
</Style.Triggers>
226+
</Style>
227+
</CheckBox.Style>
228+
</CheckBox>
229+
<Button HorizontalAlignment="Right"
230+
Command="{Binding SaveIconCommand}"
231+
Content="_Save" />
232+
</Grid>
233+
210234
</StackPanel>
211235
</materialDesign:PopupBox>
212236
</StackPanel>

0 commit comments

Comments
 (0)