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.
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: