BoolToValueConverter in a WPF window is just not working. I’ve tried everything and spent the whole day trying to figure this out…

I've tried putting the BoolToValueConverter class everywhere and nothing seems to work. The XAML just doesn't recognize it.

public class BoolToValueConverter : IValueConverter { public object TrueValue { get; set; } public object FalseValue { get; set; } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { { if (value == null) return FalseValue; else return (bool)value ? TrueValue : FalseValue; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value != null && value.Equals(TrueValue); } } 

The XAML resource contains

 <BoolToValueConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/> <BoolToValueConverter x:Key="MinorsPerMajorConverter" TrueValue="4" FalseValue="2"/> 

The actual use in XAML comes in one of the elements as a property setter

 <Setter Property="MinorsPerMajor" Value="{Binding IsFirstChartPane, Converter={StaticResource MinorsPerMajorConverter}}"/> <Setter Property="MaxAutoTicks" Value="{Binding IsFirstChartPane, Converter={StaticResource MaxAutoTicksConverter}}"/> <Setter Property="GrowBy" Value="{Binding IsFirstChartPane, Converter={StaticResource GrowByConverter}}"/> 

I've literally spend almost 10 hours on fixing this shitty part. I've been trying to build charts using SciChart and while I got one pane charts without alot of trouble, getting the multipanes to work has been horrendous. It's designed super awkward and nothing I do makes it work right.

by pope_says via /r/csharp

Leave a Reply