Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 637597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:38:28+00:00 2026-05-13T20:38:28+00:00

I have a simple silverlight toolkit Chart and a standard Slider in the same

  • 0

I have a simple silverlight toolkit Chart and a standard Slider in the same control. I want the Chart to be updated whenever the slider value changes. This oughta be simple. I tried binding to the .ValueChanged event on the slider but this appears to fire far too often (eg: multiple times while the slider is still in motion). I’m only interested in the value of the slider when it has come to a stop. The performance is terrible if I update as often as the event is fired. So I added a couple of handlers to the .MouseLeftButtonUp and .MouseLeftButtonDown events that should lock or unlock the logic for updating the chart. Unfortunately .MouseLeftButtonDown fails to fire (breakpoints within the handler don’t get hit). So that route appears to be a non-starter as well.

I’m quite new to silverlight so I’m looking for constructive criticism of the approach as well as possible solutions. Cheers!

MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Input;

namespace ControlledModelView.Media
{
    public partial class MainPage : UserControl
    {
        readonly Dictionary<KeyValuePair<int, int>, Dictionary<string, double>> data = new Dictionary<KeyValuePair<int, int>, Dictionary<string, double>>();
        readonly Chart chart = new Chart { VerticalAlignment = VerticalAlignment.Top };
        private static bool sliderInMotion = true;
        public MainPage()
        {
            InitializeComponent();
            var rng = new Random();
            for (var i = 0; i < 4; i++)
                for (var d = -1; d >= -31; d--)
                    data.Add(new KeyValuePair<int, int>(i, d), GetRandomData(rng));

            var slider = new Slider { LargeChange = 7, SmallChange = 1, Minimum = -31, Maximum = -1, Value = -1, VerticalAlignment = VerticalAlignment.Bottom };
            slider.ValueChanged += SliderValueChanged;
            slider.MouseLeftButtonUp += SliderRelease;
            slider.MouseLeftButtonDown += SliderLock;
            DrawLineChart(-1);
            LayoutRoot.Children.Add(chart);
            LayoutRoot.Children.Add(slider);
        }

        static void SliderLock(object sender, MouseButtonEventArgs e)
        {
            sliderInMotion = true;
        }

        static void SliderRelease(object sender, MouseButtonEventArgs e)
        {
            sliderInMotion = false;
        }

        void SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if(!sliderInMotion)
                DrawLineChart((int)e.NewValue);
        }

        private void DrawLineChart(int day)
        {
            chart.Series.Clear();
            for (var seriesIndex = 0; seriesIndex < 4; seriesIndex++)
            {
                chart.Series.Add(new LineSeries
                {
                    ItemsSource = data[new KeyValuePair<int, int>(seriesIndex, day)],
                    DependentValuePath = "Value",
                    IndependentValuePath = "Key",
                    AnimationSequence = AnimationSequence.Simultaneous,
                    Name = "Line" + seriesIndex,
                    Title = "Line" + seriesIndex,
                    IsSelectionEnabled = false,
                    Visibility = Visibility.Visible,
                    IsEnabled = true
                });
            }
        }

        static Dictionary<string, double> GetRandomData(Random rng)
        {
            var data = new Dictionary<string, double>();
            for (var year = 1995; year < DateTime.Now.Year; year ++)
                data.Add(year.ToString(), 500000 * rng.NextDouble());
            return data;
        }
    }
}

MainPage.xaml:

<UserControl x:Class="ControlledModelView.Media.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot" />
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:38:28+00:00Added an answer on May 13, 2026 at 8:38 pm

    This seems to be a prime example for the RX framework (IObservable), if you are able to use it.
    One of the standard samples lists filtering events, by coordinates (for MouseClick events in a region of interest). You could use that exactly for your sample.

    See this question for some details. Get it here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.