Hello,
So here's my problem.
I'm building an extended control based of a SemiCircleGauge. That gauge includes 3 ranges that are always visible, but with min and max value set at runtime.
There is also a fourth range that may or may not be visible, property also set at runtime.
I can bind every other value the way I want to, but not the visibility property. For some reason, it always shows regardless of the value I sent it.
Here's all related code :
XAML of the custom control
Code behind of the dependency property
Converter
Call of the custom control
Diag trace of the binding
Please feel free to point out my mistake, I must be missing something somewhere. And I'd really like to avoid setting the visibility in code behind
Thank you
So here's my problem.
I'm building an extended control based of a SemiCircleGauge. That gauge includes 3 ranges that are always visible, but with min and max value set at runtime.
There is also a fourth range that may or may not be visible, property also set at runtime.
I can bind every other value the way I want to, but not the visibility property. For some reason, it always shows regardless of the value I sent it.
Here's all related code :
XAML of the custom control
<
telerik:SemicircleNorthScale
x:Name
=
"RudderGaugeScale"
SweepAngle
=
"140"
StartAngle
=
"200"
ShowFirstLabel
=
"False"
ShowLastLabel
=
"False"
LabelRotationMode
=
"None"
MiddleTicks
=
"1"
MajorTickStep
=
"5"
EndWidth
=
"0.2"
StartWidth
=
"0.2"
FontSize
=
"9.333"
FontWeight
=
"Bold"
Foreground
=
"White"
LabelLocation
=
"OverOutside"
MajorTickLocation
=
"CenterInside"
MiddleTickStroke
=
"#00000000"
MinorTickBackground
=
"#00000000"
MajorTickStroke
=
"White"
MiddleTickBackground
=
"#00000000"
MajorTickBackground
=
"White"
MajorTickUseRangeColor
=
"True"
MinorTickStroke
=
"#01FFFFFF"
MajorTickStrokeThickness
=
"1"
>
<
telerik:SemicircleNorthScale.Resources
>
<
helpers:BindingProxy
x:Key
=
"proxy"
Data
=
"{Binding ElementName=RudderGauge}"
/>
</
telerik:SemicircleNorthScale.Resources
>
<
telerik:SemicircleNorthScale.Min
>
<
MultiBinding
Converter
=
"{StaticResource AngleScaleDisplayConverter}"
>
<
Binding
ElementName
=
"RudderGauge"
Path
=
"MinValue"
/>
<
Binding
ElementName
=
"RudderGauge"
Path
=
"DeadAngle"
/>
</
MultiBinding
>
</
telerik:SemicircleNorthScale.Min
>
<
telerik:SemicircleNorthScale.Max
>
<
MultiBinding
Converter
=
"{StaticResource AngleScaleDisplayConverter}"
>
<
Binding
ElementName
=
"RudderGauge"
Path
=
"MaxValue"
/>
<
Binding
ElementName
=
"RudderGauge"
Path
=
"DeadAngle"
/>
</
MultiBinding
>
</
telerik:SemicircleNorthScale.Max
>
<
telerik:SemicircleNorthScale.Ranges
>
<
telerik:GaugeRange
x:Name
=
"DangerZone1"
Background
=
"{Binding Path=ColorDanger, ElementName=RudderGauge, Converter={StaticResource ColorConverter}}"
Min
=
"{Binding ElementName=RudderGaugeScale, Path=Min}"
Max
=
"{Binding ElementName=RudderGauge, Path=DangerMin}"
StartWidth
=
"0.8"
/>
<
telerik:GaugeRange
x:Name
=
"DefaultRange"
Min
=
"{Binding ElementName=RudderGauge, Path=DangerMin}"
Max
=
"{Binding ElementName=RudderGauge, Path=DangerMax}"
Background
=
"{Binding ColorDisplay, ElementName=RudderGauge, Converter={StaticResource ColorConverter}}"
StartWidth
=
"0.8"
/>
<
telerik:GaugeRange
x:Name
=
"Sector2"
Min
=
"{Binding ElementName=RudderGauge, Path=Sector2Value}"
Max
=
"{Binding ElementName=RudderGauge, Path=DangerMax}"
Background
=
"{Binding ColorSector2, ElementName=RudderGauge, Converter={StaticResource ColorConverter}}"
Visibility
=
"{Binding Path=Data.DisplaySector2, ElementName=RudderGauge, Converter={StaticResource VisibilityConverter} diagnostics:PresentationTraceSources.TraceLevel=High}"
StartWidth
=
"0.8"
/>
<
telerik:GaugeRange
x:Name
=
"DangerZone2"
Min
=
"{Binding ElementName=RudderGauge, Path=DangerMax}"
Max
=
"{Binding ElementName=RudderGaugeScale, Path=Max}"
Background
=
"{Binding ColorDanger, ElementName=RudderGauge, Converter={StaticResource ColorConverter}}"
StartWidth
=
"0.8"
/>
</
telerik:SemicircleNorthScale.Ranges
>
<
telerik:SemicircleNorthScale.Indicators
>
<
telerik:Needle
Value
=
"{Binding ElementName=RudderGauge, Path=CurrentValue}"
/>
<
telerik:Marker
Value
=
"{Binding ElementName=RudderGauge, Path=SetPoint}"
Visibility
=
"{Binding ElementName=RudderGauge, Path=DisplaySetPoint, Converter={StaticResource VisibilityConverter}}"
/>
</
telerik:SemicircleNorthScale.Indicators
>
</
telerik:SemicircleNorthScale
>
Code behind of the dependency property
public
static
DependencyProperty DisplaySector2Property = DependencyProperty.Register(
"DisplaySector2"
,
typeof
(
bool
),
typeof
(ECARudderGauge),
new
PropertyMetadata(DisplaySector2PropertyChanged));
public
bool
DisplaySector2
{
get
{
return
(
bool
)GetValue(DisplaySector2Property); }
set
{ SetValue(DisplaySector2Property, value); }
}
private
static
void
DisplaySector2PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
((ECARudderGauge)o).OnDisplaySector2PropertyChanged((
bool
)e.NewValue);
}
private
void
OnDisplaySector2PropertyChanged(
bool
newValue)
{
DisplaySector2 = newValue;
}
Converter
using
System;
using
System.Windows;
using
System.Windows.Data;
using
System.Globalization;
namespace
ECAControls.Converters
{
public
class
VisibilityConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
bool
param = (
bool
)value;
if
(param)
return
Visibility.Visible;
else
return
Visibility.Collapsed;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
Visibility state = (Visibility)value;
if
(state == Visibility.Visible)
return
true
;
else
return
false
;
}
}
}
Call of the custom control
<
eca:ECARudderGauge
x:Name
=
"test1"
Grid.Row
=
"0"
Grid.Column
=
"1"
MinValue
=
"{Binding Path=Rudder.MinValue}"
MaxValue
=
"{Binding Path=Rudder.MaxValue}"
Steps
=
"{Binding Path=Rudder.Steps, Mode=TwoWay}"
CurrentValue
=
"{Binding Path=Rudder.CurrentValue, Mode=TwoWay}"
SetPoint
=
"{Binding Path=Rudder.SetPoint, Mode=TwoWay}"
DisplaySetPoint
=
"{Binding Path=Rudder.DisplaySetPoint, Mode=TwoWay}"
ValidateMeasure
=
"{Binding Path=Rudder.ValidateMeasure, Mode=TwoWay}"
StopValue
=
"{Binding Path=Rudder.StopValue, Mode=TwoWay}"
Sector2Value
=
"{Binding Path=Rudder.Sector2Value, Mode=TwoWay}"
DangerMin
=
"{Binding Path=Rudder.DangerMin, Mode=TwoWay}"
DangerMax
=
"{Binding Path=Rudder.DangerMax, Mode=TwoWay}"
DeadAngle
=
"{Binding Path=Rudder.DeadAngle, Mode=TwoWay}"
DisplaySector2
=
"{Binding Path=Rudder.DisplaySector2, Mode=TwoWay}"
Text1
=
"{Binding Path=Rudder.Text1, Mode=TwoWay}"
Text2
=
"{Binding Path=Rudder.Text2, Mode=TwoWay}"
ColorDisplay
=
"{Binding Path=Rudder.ColorDisplay, Mode=TwoWay}"
ColorValue
=
"{Binding Path=Rudder.ColorValue, Mode=TwoWay}"
ColorScale
=
"{Binding Path=Rudder.ColorScale, Mode=TwoWay}"
ColorSetPoint
=
"{Binding Path=Rudder.ColorSetPoint, Mode=TwoWay}"
ColorStop
=
"{Binding Path=Rudder.ColorStop, Mode=TwoWay}"
ColorSector2
=
"{Binding Path=Rudder.ColorSector2, Mode=TwoWay}"
ColorDanger
=
"{Binding Path=Rudder.ColorDanger, Mode=TwoWay}"
ColorNeedle1
=
"{Binding Path=Rudder.ColorNeedle1, Mode=TwoWay}"
ColorNeedle2
=
"{Binding Path=Rudder.ColorNeedle2, Mode=TwoWay}"
ForeColorCurrentVal
=
"{Binding Path=Rudder.ForeColorCurrentVal, Mode=TwoWay}"
BackColorCurrentVal
=
"{Binding Path=Rudder.BackColorCurrentVal, Mode=TwoWay}"
/>
Diag trace of the binding
01.
System.Windows.Data Warning: 56 : Created BindingExpression (hash=32089967) for Binding (hash=25935173)
02.
System.Windows.Data Warning: 58 : Path: 'DisplaySector2'
03.
System.Windows.Data Warning: 60 : BindingExpression (hash=32089967): Default mode resolved to OneWay
04.
System.Windows.Data Warning: 61 : BindingExpression (hash=32089967): Default update trigger resolved to PropertyChanged
05.
System.Windows.Data Warning: 62 : BindingExpression (hash=32089967): Attach to Telerik.Windows.Controls.Gauge.GaugeRange.Visibility (hash=11099805)
06.
System.Windows.Data Warning: 64 : BindingExpression (hash=32089967): Use Framework mentor <
null
>
07.
System.Windows.Data Warning: 67 : BindingExpression (hash=32089967): Resolving source
08.
System.Windows.Data Warning: 69 : BindingExpression (hash=32089967): Framework mentor not found
09.
System.Windows.Data Warning: 65 : BindingExpression (hash=32089967): Resolve source deferred
10.
System.Windows.Data Warning: 95 : BindingExpression (hash=32089967): Got InheritanceContextChanged event from GaugeRange (hash=11099805)
11.
System.Windows.Data Warning: 67 : BindingExpression (hash=32089967): Resolving source
12.
System.Windows.Data Warning: 70 : BindingExpression (hash=32089967): Found data context element: <
null
> (OK)
13.
System.Windows.Data Warning: 74 : Lookup name RudderGauge: queried SemicircleNorthScale (hash=21772565)
14.
System.Windows.Data Warning: 78 : BindingExpression (hash=32089967): Activate with root item ECARudderGauge (hash=61735358)
15.
System.Windows.Data Warning: 108 : BindingExpression (hash=32089967): At level 0 - for ECARudderGauge.DisplaySector2 found accessor DependencyProperty(DisplaySector2)
16.
System.Windows.Data Warning: 104 : BindingExpression (hash=32089967): Replace item at level 0 with ECARudderGauge (hash=61735358), using accessor DependencyProperty(DisplaySector2)
17.
System.Windows.Data Warning: 101 : BindingExpression (hash=32089967): GetValue at level 0 from ECARudderGauge (hash=61735358) using DependencyProperty(DisplaySector2): 'False'
18.
System.Windows.Data Warning: 80 : BindingExpression (hash=32089967): TransferValue - got raw value 'False'
19.
System.Windows.Data Warning: 82 : BindingExpression (hash=32089967): TransferValue - user's converter produced 'Collapsed'
20.
System.Windows.Data Warning: 89 : BindingExpression (hash=32089967): TransferValue - using final value 'Collapsed'
21.
System.Windows.Data Warning: 79 : BindingExpression (hash=32089967): Deactivate
22.
System.Windows.Data Warning: 103 : BindingExpression (hash=32089967): Replace item at level 0 with {NullDataItem}
23.
System.Windows.Data Warning: 63 : BindingExpression (hash=32089967): Detach
Please feel free to point out my mistake, I must be missing something somewhere. And I'd really like to avoid setting the visibility in code behind
Thank you