Create Gauge in code w/ CustomTickMark

6 posts, 0 answers
  1. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 08 Sep 2011 Link to this post

    I am creating the Gauges in code (based on a config file) with a Scale, Ranges, and Indicator Needle... mostly from these two examples: http://www.telerik.com/community/forums/wpf/gauges/how-to-build-and-create-dynamic-indicator-in-vb-code-instead-of-xml.aspx and http://www.telerik.com/community/forums/wpf/gauges/adding-gauge-only-with-code.aspx. It works well so far.
    I would also like to add a CustomTickMark to the Gauges similar to this post... http://www.telerik.com/community/forums/wpf/gauges/how-do-i-make-a-label-inside-a-gauge.aspx but  I need to do it in code rather than XAML. There are several variations of the code I have tried below... none of them seem to work. No label is displayed and also, it throws an error (below) when it's run.

    Any help/info/example would be very much appreciated.
    Dim tl As New TickList
    tl.Name = "ticklist" & gauges.Count.ToString
    Dim ctm As New CustomTickMark
    ctm.Name = "CustomTickMark" & gauges.Count.ToString
    ctm.Template = GetInternalLabel()
     
    tl.Items.Add(ctm)
    scale.Ticks.Add(tl)
    Private Function GetInternalLabel() As ControlTemplate
           Dim l As FrameworkElementFactory = New FrameworkElementFactory(GetType(TextBlock))
           'l.SetValue(Ellipse.FillProperty, Brushes.AliceBlue)
           'l.SetValue(Ellipse.MarginProperty, New Thickness(2))
           l.SetValue(TextBlock.TextProperty, "Test")
     
     
           Dim cv As FrameworkElementFactory = New FrameworkElementFactory(GetType(Canvas))
     
           'grid.SetValue(Grid.MarginProperty, new Thickness(5));
     
     
           cv.AppendChild(l)
     
     
           Dim ct As New ControlTemplate(GetType(CustomTickMark))
     
           'Dim cp As New ContentPresenter
           'cp.Name = "cp" & gauges.Count.ToString
           ''Dim cv As New Canvas
           ''cv.Name = "cv" & gauges.Count.ToString
           'cp.Content = cv
           ''Dim l As New TextBlock
           ''l.Name = "label" & gauges.Count.ToString
           ''l.Text = "test"
           ''cv.Children.Add(l)
     
           ct.VisualTree = l
     
     
           Return ct
       End Function
    System.ArgumentNullException was unhandled
      Message=Value cannot be null.
    Parameter name: reference
      Source=PresentationCore
      ParamName=reference
      StackTrace:
           at System.Windows.Media.VisualTreeHelper.HitTest(Visual reference, Point point)
           at Telerik.Windows.Controls.Gauges.GaugeHelper.CheckPointOver(FrameworkElement element, Point point) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\Gauge\GaugeHelper.cs:line 62
           at Telerik.Windows.Controls.Gauges.GaugeHelper.CheckMouseOver(FrameworkElement element, MouseEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\Gauge\GaugeHelper.cs:line 33
           at Telerik.Windows.Controls.Gauges.ScaleBase.ScaleBase_MouseMove(Object sender, MouseEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\Gauge\Scales\ScaleBase.cs:line 1426
           at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
           at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
           at System.Windows.Input.InputManager.ProcessStagingArea()
           at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
           at System.Windows.Input.MouseDevice.Synchronize()
           at System.Windows.Input.MouseDevice.PostProcessInput(Object sender, ProcessInputEventArgs e)
           at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
           at System.Windows.Input.InputManager.ProcessStagingArea()
           at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
           at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
           at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
           at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.Run()
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at WPFDashboard.Application.Main() in C:\Users\jcrumpton\Documents\Visual Studio 2010\Projects\WPFDashboard\WPFDashboard\obj\x86\Debug\Application.g.vb:line 64
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:
  2. Sia
    Admin
    Sia avatar
    667 posts

    Posted 13 Sep 2011 Link to this post

    Hi John Crumpton,

    Please try to change your code as follows:
    Dim tl As New TickList
    tl.Name = "ticklist"
    Dim ctm As New CustomTickMark
    ctm.Value = 50
    ctm.Name = "CustomTickMark"
    ctm.Template = GetInternalLabel()
     
    tl.Items.Add(ctm)
    scale.Items.Add(tl)

    and let us know whether this solves your problem.

    Best wishes,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 13 Sep 2011 Link to this post

    no, sorry... same error.
    it seems to be a dependency property named "reference"... but I don't know where/how to set it.
  5. Sia
    Admin
    Sia avatar
    667 posts

    Posted 13 Sep 2011 Link to this post

    Hi John Crumpton,

    Can you please send us a sample application reproducing your problem, because in our local tests everything works as expected?

    Kind regards,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 13 Sep 2011 Link to this post

    I tried to create a ticket (to upload the project files) but for some reason it only allows me to select Winforms controls for a category... I figured it would just get lost if I do that. Anyway, There's not a lot of code involved... all of it is below.

    related... I didn't notice this originally because I had so many gauges on screen, but when I cut it back to just a single gauge to demo the issue, I notice that the error doesn't occur until you mouse over the gauge, however the label is not displayed.

    Please advise as to how I should proceed w/ uploading the project files.

    XAML:
    <Window x:Class="MainWindow"
        Title="MainWindow" Height="350" Width="525" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
        <Grid x:Name="bgGrid"></Grid>
    </Window>

    VB:
    Imports Telerik.Windows.Controls.Gauges
     
    Class MainWindow
     
        Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
            AddRadialGauge()
        End Sub
     
        Private Sub AddRadialGauge()
            Dim scale As RadialScale
            Dim needle As Needle
            Dim sp As New StackPanel
            sp.Orientation = Orientation.Vertical
     
            Dim radGauge = New Telerik.Windows.Controls.RadGauge()
            radGauge.Name = "dashboardGauge"
            radGauge.Width = 250
            radGauge.Height = 250
            sp.Width = 250
            sp.Height = 250
            sp.Children.Add(radGauge)
            
            bgGrid.Children.Add(sp)
     
            Canvas.SetLeft(sp, 200)
            Canvas.SetTop(sp, 200)
     
            Dim gauge = New RadialGauge()
     
            radGauge.Content = gauge
     
            scale = New RadialScale()
            scale.Name = "scale"
            scale.Min = 0
            scale.Max = 180
            scale.MinorTicks = 4
            scale.MiddleTicks = 4
            scale.MajorTicks = 10
            scale.Radius = 0.65
     
            gauge.Items.Add(scale)
     
            Dim tl As New TickList
            tl.Name = "ticklist" ' & gauges.Count.ToString
            Dim ctm As New CustomTickMark
            ctm.Name = "CustomTickMark" ' & gauges.Count.ToString
            ctm.Value = 50
            ctm.Template = GetInternalLabel()
     
            tl.Items.Add(ctm)
            scale.Ticks.Add(tl)
     
     
     
     
            Dim IndicatorList1 = New IndicatorList()
            scale.Items.Add(IndicatorList1)
     
            needle = New Needle()
            needle.Name = "Needle"
     
            scale.Indicators.Add(needle)
            Me.RegisterName(needle.Name, needle)
        End Sub
     
        Private Function GetInternalLabel() As ControlTemplate
            Dim l As FrameworkElementFactory = New FrameworkElementFactory(GetType(TextBlock))
            l.SetValue(TextBlock.TextProperty, "Test")
     
            Dim cv As FrameworkElementFactory = New FrameworkElementFactory(GetType(Canvas))
     
            cv.AppendChild(l)
     
            Dim ct As New ControlTemplate(GetType(CustomTickMark))
     
            ct.VisualTree = l
     
            Return ct
        End Function
    End Class

  7. Sia
    Admin
    Sia avatar
    667 posts

    Posted 16 Sep 2011 Link to this post

    Hello John Crumpton,

    Please review the modified version of your project. Only the changes which I mentioned below are applied.
    I hope this helps.

    Greetings,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready