Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Gauges > Dynamic number of NumberPosition items

Not answered Dynamic number of NumberPosition items

Feed from this thread
  • Miha Markic Miha Markic's avatar

    Posted on Dec 17, 2010 (permalink)

    Is there a way to dynamically specify number of NumberPosition items within NumericIndicator in XAML?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Miha Markic,

    In fact the numeric indicator is an items control. So, you can change its positions using the Items property.
    The sample code below adds positions dynamically according to digits of generated value.
    <Window x:Class="DynamicNumberOfPositions.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid Background="White">
            <Grid Width="200" Height="80">
                <telerik:NumericScale Name="scale"
                                      Min="0" Max="10000">
                    <telerik:IndicatorList>
                        <telerik:NumericIndicator x:Name="numericIndicator"
                                    Top="0"
                                    Left="0"
                                    Padding="5"
                                    BorderThickness="0"
                                    RelativeHeight="1"
                                    RelativeWidth="1"
                                    TemplatePrefix="HexagonalSevenSegs"
                                    Foreground="Blue"
                                    Background="Transparent"
                                    Format="{}{0:F0}">
                        </telerik:NumericIndicator>
                    </telerik:IndicatorList>
                </telerik:NumericScale>
            </Grid>
        </Grid>
    </Window>
    using System;
    using System.Windows;
    using System.Windows.Threading;
    using Telerik.Windows.Controls.Gauges;
      
    namespace DynamicNumberOfPositions
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            DispatcherTimer timer;
            Random rnd;
      
            public MainWindow()
            {
                InitializeComponent();
                this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            }
      
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                rnd = new Random();
                timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick += new EventHandler(timer_Tick);
                timer.Start();
            }
      
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
      
                double value = rnd.NextDouble() * (scale.Max - scale.Min);
                int intValue = (int)Math.Round(value, 0);
                int positions = intValue.ToString().Length;
      
                if (positions != numericIndicator.Items.Count)
                {
                    numericIndicator.Items.Clear();
      
                    for (int i = 0; i < positions; i++)
                    {
                        numericIndicator.Items.Add(new NumberPosition());
                    }
                }
      
                numericIndicator.Value = intValue;
      
                timer.Start();
            }
        }
    }

    All the best,
    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF

    Reply

  • pravi avatar

    Posted on Jul 22, 2011 (permalink)

    Hi,

    I have try this but I am not getting the digits, below is my code, please suggest where i am going wrong ?

     

    if (numericIndicatorIncentives.Items.Count != strCustomerIncentives.Length)
                {
                    numericIndicatorIncentives.Items.Clear();
                    for (int i = 0; i < strCustomerCost.Length; i++)
                    {
                        NumberPosition numberPosition = new NumberPosition();
                        numberPosition.Margin = new Thickness(2, -1, 0, 1);
                        numberPosition.Background = new SolidColorBrush(Colors.Transparent);
      
                        numberPosition.FontSize = 24;
                        numberPosition.Height = 45;
                        numberPosition.Width = 23;
                        numberPosition.Background = new SolidColorBrush(Colors.Transparent);
                        numberPosition.BorderBrush = new SolidColorBrush(Colors.Orange);
                        numberPosition.BorderThickness = new Thickness(1);
      
                        //numberPosition.Background = new Brush();
                        numberPosition.CornerRadius = new CornerRadius (0);
                        numericIndicatorIncentives.Items.Add(numberPosition);
                    }
                }
      
                numericIndicatorIncentives.Value = 100000; //Convert.ToInt32(strCustomerIncentives);

    Reply

  • Andrey Andrey admin's avatar

    Posted on Jul 27, 2011 (permalink)

    Hello Pravi,

    It is very complicated and is hard for us to reproduce the problemfrom the code snippet you sent. Could you, please, provide us a small sample solution which reproduces it?

    Greetings,
    Andrey Murzov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Gauges > Dynamic number of NumberPosition items
Related resources for "Dynamic number of NumberPosition items"

WPF Gauge Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]