This is a migrated thread and some comments may be shown as answers.

GaugeRange and Caliburn.Micro issue and workaround

3 Answers 98 Views
Gauge
This is a migrated thread and some comments may be shown as answers.
Sebastian
Top achievements
Rank 1
Sebastian asked on 15 Mar 2012, 11:38 AM
Hi,

Im using the RadSemicircleNorthGauge in a MVVM Silvelright 4 application and need to define some ranges for the control. I added some GaugeRanges in Blend and the designer showed them as I added them without any problems. But when i began to run the application i started getting some weird errors. So i began commenting our some code and finally found out that it was the GaugeRanges defined in xaml that where acting up with Caliburn.Micro.

The error:
Reference is not a valid visual DependencyObject.

{System.InvalidOperationException: Reference is not a valid visual DependencyObject.
   at System.Windows.Media.VisualTreeHelper.GetRelative(DependencyObject reference, RelativeKind relativeKind)
   at System.Windows.Media.VisualTreeHelper.GetChildrenCount(DependencyObject reference)
   at Caliburn.Micro.BindingScope.<.cctor>b__3(DependencyObject elementInScope)
   at Caliburn.Micro.ViewModelBinder.<.cctor>b__3(Object viewModel, DependencyObject view, Object context)
   at Caliburn.Micro.Bootstrapper.DisplayRootViewFor(Application application, Type viewModelType)
   at Caliburn.Micro.Bootstrapper`1.OnStartup(Object sender, StartupEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)}

Code that gives the error in Caliburn.Micro:
current in this case is {Telerik.Windows.Controls.Gauge.GaugeRange}
BindingScope.cs
 var childCount = VisualTreeHelper.GetChildrenCount(current); 

This is the code that gave me the error:
<telerik:RadSemicircleNorthGauge Grid.Row="1" Style="{StaticResource RadSemiCircleNorthGaugeStyle}">
           <telerik:RadialScale x:Name="radialScale" MajorTickStroke="{StaticResource BackgroundBlack}"
                                            Foreground="{x:Null}" MiddleTickStroke="{x:Null}"
                                            MiddleTickBackground="{x:Null}" MajorTickBackground="{x:Null}"
                                            MinorTickBackground="{x:Null}" MinorTickStroke="{x:Null}">
               <telerik:RadialScale.Ranges>
                   <telerik:GaugeRange Min="0" Max="32" TickBackground="{StaticResource ControlGreen}"
                                                           Background="{StaticResource BackgroundBlack}" StartWidth="0.15" EndWidth="0.15"/>
                   <telerik:GaugeRange Min="34" Max="65"  TickBackground="{StaticResource ControlGreen}"
                                                           Background="{StaticResource ControlGreen}" StartWidth="0.15" EndWidth="0.15"/>
                   <telerik:GaugeRange Min="67" Max="100" TickBackground="{StaticResource ControlGreen}"
                                                           Background="{StaticResource BackgroundBlack}" StartWidth="0.15" EndWidth="0.15"/>
               </telerik:RadialScale.Ranges>
               <telerik:RadialScale.Indicators>
                   <telerik:Needle IsAnimated="True" Value="91" Style="{StaticResource GaugeNeedleStyle}" />
               </telerik:RadialScale.Indicators>
           </telerik:RadialScale>
       </telerik:RadSemicircleNorthGauge>

My workaround:
I added the ranges to the Gauge in code behind.
public partial class TestView : UserControl
   {
       public TestView ()
       {
           InitializeComponent();
           this.Loaded += new RoutedEventHandler(TestView _Loaded);
       }
 
       void TestView _Loaded(object sender, RoutedEventArgs e)
       {
           this.Dispatcher.BeginInvoke(() =>
               {
                   this.GaugeRadialScale.Ranges.Add(new GaugeRange() { Min = 0, Max = 32, Background = new SolidColorBrush(Colors.Magenta), StartWidth = 0.15, EndWidth = 0.15, TickBackground = new SolidColorBrush(Colors.Blue) });
                   this.GaugeRadialScale.Ranges.Add(new GaugeRange() { Min = 34, Max = 65, Background = new SolidColorBrush(Colors.Magenta), StartWidth = 0.15, EndWidth = 0.15, TickBackground = new SolidColorBrush(Colors.Blue) });
                  this.GaugeRadialScale.Ranges.Add(new GaugeRange() { Min = 67, Max = 100, Background = new SolidColorBrush(Colors.Magenta), StartWidth = 0.15, EndWidth = 0.15, TickBackground = new SolidColorBrush(Colors.Blue) });
               });
       }
   }

Below is a link to a sample project that will give the error.
http://www.burgundi.com/wp-content/uploads/2012/03/CaliburnGaugeTest.zip

Is this something that can be resolved since i don´t want any code in my code behind?

Regards,
Sebastian

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 Mar 2012, 09:08 AM
Hello Sebastian,

Unfortunately we are not familiar with the Caliburn.Micro library. Also supporting its functionality is out of the support scope for the gauge control.
The exception within this library occurs because the GaugeRange is a data object (not a visual).

Greetings,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Sebastian
Top achievements
Rank 1
answered on 20 Mar 2012, 09:12 AM
Hi Andrey,

I understand, i was hoping someone else would have found a solution, not necessarily within the Telerik controls.
But thanks for the info.

Regards,
Sebastian
0
Doug
Top achievements
Rank 1
Veteran
answered on 15 Feb 2015, 03:51 AM
Hi Sebastian,

I realize this is an old post but your example solution helped me resolve this same issue 3 years later.  Just wanted to say Thanks!

-Doug-
Tags
Gauge
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Sebastian
Top achievements
Rank 1
Doug
Top achievements
Rank 1
Veteran
Share this question
or