I want to use WPF DataTrigger to check value greater than X. I know that this is only possible with IValueConverter. I have found many C# examples for that, but I need it in powershell. Could someone help me translate this to powershell?
The C# code to translate:
public class CutoffConverter : IValueConverter {
public object ConvertTo(object obj, Type type) {
return ((int)obj) > Cutoff;
}
public object ConvertFrom(object obj, Type type) {
throw new NotImplementedException();
}
public int Cutoff { get; set; }
}
And the XAML
<Window.Resources>
<myNamespace:CutoffConverter x:Key="AgeConverter"/>
</Window.Resources>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Age,
Converter={StaticResource AgeConverter},
ConverterParameter=30}">
<Setter TargetName="Age" Property="Foreground" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
Sure:
You can add most any C# code this way. And you pretty much need to use C# because AFAIK you can’t implement interfaces in PowerShell script. It is more of a CLI consumer language and not so much a producer language.