Miha Markic
Top achievements
Rank 1
Miha Markic
asked on 17 Dec 2010, 02:22 PM
Is there a way to dynamically specify number of NumberPosition items within NumericIndicator in XAML?
3 Answers, 1 is accepted
0
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.
All the best,
Andrey Murzov
the Telerik team
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"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
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
0
pravi
Top achievements
Rank 1
answered on 22 Jul 2011, 03:44 PM
Hi,
I have try this but I am not getting the digits, below is my code, please suggest where i am going wrong ?
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);
0
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
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!