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

  • SEARCH
  • Home
  • 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 8611035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:16:20+00:00 2026-06-12T04:16:20+00:00

Lets say I have 3 or more Slider and each slider can have a

  • 0

Lets say I have 3 or more Slider and each slider can have a value from 0 to 100.
However I want that the sum of all slider values is <= 100. In case I have 4 slider everyones max value would be 25.

Every slider has a binding to a double variable and every time the user uses a slider (tick frequency 0.1) I calculate the sum and set other slider back or if necessary set the same slider back, so that the sum is <= 100.

The problem is, that the calculation needs a decent amount of time and in the meantime the user can set illegal values. I would like to solve this by blocking the UI until the calculation is over. Basically the opposite of the desired responsiveness.

Other ideas and suggestions to solve the slider thing are welcome.

For example 3 slider.

slider binding

public BindingList<WLCToolParameter> WLCParameter
   {
       get { return _toolParameter; }
       set { _toolParameter = value; }
   }

should be instant – not really 🙁

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MCDA.Entity;
using MCDA.Extensions;

namespace MCDA.Model
{
    class ProportionalDistributionStrategy : IWeightDistributionStrategy
    {
        public void Distribute<T>(IList<T> listOfToolParameter) where T : class, IToolParameter
        {

            if (listOfToolParameter.Count == 0)
                return;

            IToolParameter lastWeightChangedToolParameter =  lastWeightChangedToolParameter = listOfToolParameter[0].LastWeightChangedToolParameter;

            double sumOfAllWeights = listOfToolParameter.Sum(t =>t.Weight);

            //we have to rescale
            if (sumOfAllWeights > 100)
            {
                double overrun = sumOfAllWeights - 100;

                //how much do we have without the locked and the last changed?
                double availableSpace = listOfToolParameter.Where(t => t.IsLocked == false && t != lastWeightChangedToolParameter).Sum(t => t.Weight);

                //we have enough by taking from the non locked
                if (availableSpace > overrun)
                {
                    //lets remove proportional
                    double sumOfChangeableWeights = listOfToolParameter.Where(t => t.IsLocked == false && t != lastWeightChangedToolParameter).Sum(t => t.Weight);

                    //in case we have only one element that is suitable we can directly remove all from this one
                    if (listOfToolParameter.Where(t => t.IsLocked == false && t.Weight > 0 && t != lastWeightChangedToolParameter).Count() == 1)
                    {
                        listOfToolParameter.Where(t => t.IsLocked == false && t.Weight > 0 && t != lastWeightChangedToolParameter).ForEach(t => t.Weight = t.Weight - overrun);
                        return;
                    }
                    listOfToolParameter.Where(t => t.IsLocked == false && t.Weight > 0 && t != lastWeightChangedToolParameter).ForEach(t => t.Weight = t.Weight - (sumOfChangeableWeights / (sumOfChangeableWeights - t.Weight)) * overrun);
                }

                //we have to resize also the latest change, but we try to keep as much as possible of the latest change
                else
                {
                    //lets set them to zero
                    listOfToolParameter.Where(t => t.IsLocked == false && t != lastWeightChangedToolParameter).ForEach(t => t.Weight = 0);

                    //how much are we still over?
                    double stillOver = listOfToolParameter.Sum(t => t.Weight) - 100;

                    //and cut from the last changed
                    listOfToolParameter.Where(t => t == lastWeightChangedToolParameter).ForEach(t => t.Weight -= stillOver);
                }
            }
        }
    }
}
  • 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-06-12T04:16:21+00:00Added an answer on June 12, 2026 at 4:16 am

    It looks like you are not making use of data binding. Here is a simple example – just add your calculation logic to the calculating method. The UI will update itself. Note this is a crude example. I am not sure I would implement it this way. Also be careful of using decimals in your numbers. If you use this with foreign languages / regional settings with a comma as the decimal separator – it will error out.

    <Window x:Class="WpfApplication3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <StackPanel>
                <Slider Margin="10" Value="{Binding Path=Value1}" />
                <TextBlock Text="{Binding Path=Value1}" />
                <Slider Margin="10" Value="{Binding Path=Value2}" />
                <TextBlock Text="{Binding Path=Value2}" />
                <Slider Margin="10" Value="{Binding Path=Value3}" />
                <TextBlock Text="{Binding Path=Value3}" />
            </StackPanel>
    
        </Grid>
    </Window>
    

    Code Behind (MVVM approach this would be in your View Model)

    namespace WpfApplication3
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window, INotifyPropertyChanged
        {
            public MainWindow()
            {
                InitializeComponent();
                DataContext = this;
            }
    
            private double _value1;
            public double Value1
            {
                get { return _value1; }
                set
                {
                    if(value != _value1)
                    {
                        _value1 = value;
                        DoMyCalculations(_value1, _value2, _value3);
                        NotifyPropertChanged("Value1");
                    }
                }
            }
            private double _value2;
            public double Value2
            {
                get { return _value2; }
                set
                {
                    if (value != _value2)
                    {
                        _value2 = value;
                        DoMyCalculations(_value1, _value2, _value3);
                        NotifyPropertChanged("Value2");
                    }
                }
            }
            private double _value3;
            public double Value3
            {
                get { return _value3; }
                set
                {
                    if (value != _value3)
                    {
                        _value3 = value;
                        DoMyCalculations(_value1, _value2, _value3);
                        NotifyPropertChanged("Value3");
                    }
                }
            }
            private bool isCalculating = false;
            private void DoMyCalculations(double value1, double value2, double value3)
            {
                if (isCalculating)
                    return;
                isCalculating = true;
    
                // Perform logic to reset here
    
    
                isCalculating = false;
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            /// <summary>
            /// Notify of Property Changed event
            /// </summary>
            /// <param name="propertyName"></param>
            public void NotifyPropertChanged(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a server program that can accept connections from 10 (or
Lets say I have a function that needs to return some integer value. but
Lets say I have a column that has 20 rows (it's more, but the
Lets say I have a form field. Also I can dynamically add more fields,
Lets say I have a table that will never have more than 10 records.
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Lets say I have a class A that is fairly simple like this -
Lets say we have numbers from 1 to 25 and we have to choose
Lets say we have this code that runs in the constructor: Dim initVectorBytes As
Lets say I wish to make a page that can query the desired object

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.